This commit is contained in:
2026-02-08 21:51:04 +01:00
parent 04179fde77
commit df5ef074ad
3 changed files with 33 additions and 38 deletions

View File

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

View File

@@ -528,11 +528,6 @@ class Line(metaclass=PoolMeta):
if self.lots: if self.lots:
return [l for l in self.lots if l.lot_type=='virtual'][0] return [l for l in self.lots if l.lot_type=='virtual'][0]
# @fields.depends('quantity','quantity_theorical')
# def on_change_quantity(self):
# if not self.quantity_theorical:
# self.quantity_theorical = self.quantity
def get_basis_price(self): def get_basis_price(self):
price = Decimal(0) price = Decimal(0)
for pc in self.price_components: for pc in self.price_components:

View File

@@ -179,7 +179,7 @@ class ValuationBase(ModelSQL):
values = cls._build_basis_pnl(line=line, lot=lot, sale_line=None, pc=pc, sign=-1) values = cls._build_basis_pnl(line=line, lot=lot, sale_line=None, pc=pc, sign=-1)
if line.mtm: if line.mtm:
for strat in line.mtm: for strat in line.mtm:
values['mtm'] = line.get_mtm(values['qty']) values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat values['strategy'] = strat
if values: if values:
@@ -200,7 +200,7 @@ class ValuationBase(ModelSQL):
) )
if line.mtm: if line.mtm:
for strat in line.mtm: for strat in line.mtm:
values['mtm'] = line.get_mtm(values['qty']) values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat values['strategy'] = strat
if values: if values:
@@ -227,7 +227,7 @@ class ValuationBase(ModelSQL):
values = cls._build_basis_pnl(line=line, lot=sl, sale_line=sl_line, pc=pc, sign=+1) values = cls._build_basis_pnl(line=line, lot=sl, sale_line=sl_line, pc=pc, sign=+1)
if sl_line.mtm: if sl_line.mtm:
for strat in line.mtm: for strat in line.mtm:
values['mtm'] = sl_line.get_mtm(values['qty']) values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat values['strategy'] = strat
if values: if values:
@@ -248,7 +248,7 @@ class ValuationBase(ModelSQL):
) )
if sl_line.mtm: if sl_line.mtm:
for strat in sl_line.mtm: for strat in sl_line.mtm:
values['mtm'] = sl_line.get_mtm(values['qty']) values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat values['strategy'] = strat
if values: if values: