Add Fixed type component
This commit is contained in:
@@ -511,13 +511,13 @@ class MtmStrategy(ModelSQL, ModelView):
|
||||
Currency = pool.get('currency.currency')
|
||||
total = Decimal(0)
|
||||
|
||||
scenario = self.scenario
|
||||
dt = scenario.valuation_date
|
||||
|
||||
for comp in self.components:
|
||||
value = Decimal(0)
|
||||
|
||||
if comp.price_source_type == 'curve' and comp.price_index:
|
||||
scenario = self.scenario
|
||||
dt = scenario.valuation_date
|
||||
|
||||
for comp in self.components:
|
||||
value = Decimal(0)
|
||||
|
||||
if comp.price_source_type == 'curve' and comp.price_index:
|
||||
value = Decimal(
|
||||
comp.price_index.get_price(
|
||||
dt,
|
||||
@@ -526,14 +526,22 @@ class MtmStrategy(ModelSQL, ModelView):
|
||||
last=scenario.use_last_price
|
||||
)
|
||||
)
|
||||
|
||||
elif comp.price_source_type == 'matrix' and comp.price_matrix:
|
||||
value = self._get_matrix_price(comp, line, dt)
|
||||
|
||||
if comp.ratio:
|
||||
value *= Decimal(comp.ratio) / Decimal(100)
|
||||
|
||||
total += value * qty
|
||||
|
||||
elif comp.price_source_type == 'matrix' and comp.price_matrix:
|
||||
value = self._get_matrix_price(comp, line, dt)
|
||||
|
||||
elif comp.price_source_type == 'fixed':
|
||||
value = Decimal(comp.get_price(
|
||||
dt,
|
||||
line.unit,
|
||||
self.currency,
|
||||
last=scenario.use_last_price
|
||||
))
|
||||
|
||||
if comp.ratio:
|
||||
value *= Decimal(comp.ratio) / Decimal(100)
|
||||
|
||||
total += value * qty
|
||||
|
||||
return Decimal(str(total)).quantize(Decimal("0.01"))
|
||||
|
||||
@@ -691,22 +699,37 @@ class Component(ModelSQL, ModelView):
|
||||
required=False, ondelete='CASCADE'
|
||||
)
|
||||
|
||||
price_source_type = fields.Selection([
|
||||
('curve', 'Curve'),
|
||||
('matrix', 'Matrix'),
|
||||
# ('manual', 'Manual'),
|
||||
], "Price Source", required=True)
|
||||
|
||||
fix_type = fields.Many2One('price.fixtype',"Fixation type")
|
||||
ratio = fields.Numeric("%",digits=(16,7))
|
||||
price_index = fields.Many2One('price.price',"Curve")
|
||||
price_matrix = fields.Many2One('price.matrix', "Price Matrix")
|
||||
currency = fields.Function(fields.Many2One('currency.currency',"Curr."),'get_cur')
|
||||
auto = fields.Boolean("Auto")
|
||||
fallback = fields.Boolean("Fallback")
|
||||
calendar = fields.Many2One('price.calendar',"Calendar")
|
||||
nbdays = fields.Function(fields.Integer("Nb days"),'get_nbdays')
|
||||
triggers = fields.One2Many('pricing.trigger','component',"Period rules")
|
||||
price_source_type = fields.Selection([
|
||||
('curve', 'Curve'),
|
||||
('matrix', 'Matrix'),
|
||||
('fixed', 'Fixed'),
|
||||
], "Price Source", required=True)
|
||||
|
||||
fix_type = fields.Many2One('price.fixtype',"Fixation type")
|
||||
ratio = fields.Numeric("%",digits=(16,7))
|
||||
price_index = fields.Many2One('price.price',"Curve")
|
||||
price_matrix = fields.Many2One('price.matrix', "Price Matrix")
|
||||
fixed_price = fields.Numeric(
|
||||
"Fixed Price", digits=(16, 6),
|
||||
states={
|
||||
'invisible': Eval('price_source_type') != 'fixed',
|
||||
'required': Eval('price_source_type') == 'fixed',
|
||||
},
|
||||
depends=['price_source_type'])
|
||||
fixed_currency = fields.Many2One('currency.currency', "Fixed Curr.")
|
||||
currency = fields.Function(
|
||||
fields.Many2One(
|
||||
'currency.currency', "Curr.",
|
||||
states={
|
||||
'required': Eval('price_source_type') == 'fixed',
|
||||
},
|
||||
depends=['price_source_type']),
|
||||
'get_cur', setter='set_cur')
|
||||
auto = fields.Boolean("Auto")
|
||||
fallback = fields.Boolean("Fallback")
|
||||
calendar = fields.Many2One('price.calendar',"Calendar")
|
||||
nbdays = fields.Function(fields.Integer("Nb days"),'get_nbdays')
|
||||
triggers = fields.One2Many('pricing.trigger','component',"Period rules")
|
||||
pricing_date = fields.Date("Pricing date max")
|
||||
|
||||
def get_rec_name(self, name=None):
|
||||
@@ -714,16 +737,35 @@ class Component(ModelSQL, ModelView):
|
||||
return '[' + self.fix_type.name + '] ' + self.price_index.price_index
|
||||
if self.price_matrix:
|
||||
return '[' + self.fix_type.name + '] ' + self.price_matrix.name
|
||||
if self.price_source_type == 'fixed':
|
||||
return '[' + self.fix_type.name + '] Fixed'
|
||||
else:
|
||||
return '[' + self.fix_type.name + '] '
|
||||
|
||||
def get_cur(self,name):
|
||||
def get_cur(self, name=None):
|
||||
if self.price_index:
|
||||
PI = Pool().get('price.price')
|
||||
pi = PI(self.price_index)
|
||||
return pi.price_currency
|
||||
if self.price_matrix:
|
||||
return self.price_matrix.currency
|
||||
if self.price_source_type == 'fixed':
|
||||
return self.fixed_currency
|
||||
|
||||
@fields.depends(
|
||||
'price_source_type', 'price_index', 'price_matrix',
|
||||
'fixed_currency')
|
||||
def on_change_with_currency(self):
|
||||
if self.price_source_type == 'curve' and self.price_index:
|
||||
return self.get_cur()
|
||||
if self.price_source_type == 'matrix' and self.price_matrix:
|
||||
return self.get_cur()
|
||||
if self.price_source_type == 'fixed':
|
||||
return self.fixed_currency
|
||||
|
||||
@classmethod
|
||||
def set_cur(cls, components, name, value):
|
||||
cls.write(components, {'fixed_currency': value})
|
||||
|
||||
def get_calendar(self):
|
||||
if self.calendar:
|
||||
@@ -803,6 +845,17 @@ class Component(ModelSQL, ModelView):
|
||||
price_qt *= Decimal(str(rate))
|
||||
return round(price_qt, 4)
|
||||
|
||||
def _convert_fixed_price(self, price, currency):
|
||||
price_qt = Decimal(str(price or 0))
|
||||
price_currency = getattr(self, 'fixed_currency', None)
|
||||
if price_currency and currency and currency != price_currency:
|
||||
Currency = Pool().get('currency.currency')
|
||||
rates = Currency._get_rate([price_currency])
|
||||
rate = rates.get(price_currency.id)
|
||||
if rate:
|
||||
price_qt *= Decimal(str(rate))
|
||||
return round(price_qt, 4)
|
||||
|
||||
def get_price(self, price_date, unit, currency, last=False):
|
||||
if self.price_source_type == 'curve' and self.price_index:
|
||||
PI = Pool().get('price.price')
|
||||
@@ -815,6 +868,8 @@ class Component(ModelSQL, ModelView):
|
||||
if line:
|
||||
return self._convert_matrix_price(
|
||||
line.price_value, unit, currency)
|
||||
if self.price_source_type == 'fixed':
|
||||
return self._convert_fixed_price(self.fixed_price, currency)
|
||||
return Decimal(0)
|
||||
|
||||
def get_nbdays(self, name):
|
||||
|
||||
Reference in New Issue
Block a user