08.02.26
This commit is contained in:
@@ -91,7 +91,7 @@ class MtmStrategy(ModelSQL, ModelView):
|
||||
def default_active(cls):
|
||||
return True
|
||||
|
||||
def compute_mtm(self):
|
||||
def get_mtm(self,qty):
|
||||
pool = Pool()
|
||||
Currency = pool.get('currency.currency')
|
||||
total = Decimal(0)
|
||||
@@ -104,7 +104,7 @@ class MtmStrategy(ModelSQL, ModelView):
|
||||
|
||||
if comp.price_source_type == 'curve' and comp.price_curve:
|
||||
value = Decimal(
|
||||
comp.price_curve.get_price(
|
||||
comp.price_index.get_price(
|
||||
dt,
|
||||
self.purchase_line.unit,
|
||||
self.currency,
|
||||
@@ -118,41 +118,41 @@ class MtmStrategy(ModelSQL, ModelView):
|
||||
if comp.ratio:
|
||||
value *= Decimal(comp.ratio)
|
||||
|
||||
total += value
|
||||
total += value * qty
|
||||
|
||||
return total
|
||||
|
||||
def _get_matrix_price(self, comp, dt):
|
||||
MatrixLine = Pool().get('price.matrix.line')
|
||||
def _get_matrix_price(self, comp, dt):
|
||||
MatrixLine = Pool().get('price.matrix.line')
|
||||
|
||||
domain = [
|
||||
('matrix', '=', comp.price_matrix.id),
|
||||
domain = [
|
||||
('matrix', '=', comp.price_matrix.id),
|
||||
]
|
||||
|
||||
if self.purchase_line:
|
||||
domain += [
|
||||
('origin', '=', self.purchase_line.from_location),
|
||||
('destination', '=', self.purchase_line.to_location),
|
||||
]
|
||||
|
||||
if self.purchase_line:
|
||||
domain += [
|
||||
('origin', '=', self.purchase_line.from_location),
|
||||
('destination', '=', self.purchase_line.to_location),
|
||||
]
|
||||
lines = MatrixLine.search(domain)
|
||||
if lines:
|
||||
return Decimal(lines[0].price_value)
|
||||
|
||||
lines = MatrixLine.search(domain)
|
||||
if lines:
|
||||
return Decimal(lines[0].price_value)
|
||||
|
||||
return Decimal(0)
|
||||
return Decimal(0)
|
||||
|
||||
def run_daily_mtm():
|
||||
Strategy = Pool().get('mtm.strategy')
|
||||
Snapshot = Pool().get('mtm.snapshot')
|
||||
def run_daily_mtm():
|
||||
Strategy = Pool().get('mtm.strategy')
|
||||
Snapshot = Pool().get('mtm.snapshot')
|
||||
|
||||
for strat in Strategy.search([('active', '=', True)]):
|
||||
amount = strat.compute_mtm()
|
||||
Snapshot.create([{
|
||||
'strategy': strat.id,
|
||||
'valuation_date': strat.scenario.valuation_date,
|
||||
'amount': amount,
|
||||
'currency': strat.currency.id,
|
||||
}])
|
||||
for strat in Strategy.search([('active', '=', True)]):
|
||||
amount = strat.compute_mtm()
|
||||
Snapshot.create([{
|
||||
'strategy': strat.id,
|
||||
'valuation_date': strat.scenario.valuation_date,
|
||||
'amount': amount,
|
||||
'currency': strat.currency.id,
|
||||
}])
|
||||
|
||||
class Mtm(ModelSQL, ModelView):
|
||||
"MtM Component"
|
||||
|
||||
Reference in New Issue
Block a user