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):
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"

View File

@@ -526,12 +526,7 @@ class Line(metaclass=PoolMeta):
def getVirtualLot(self):
if self.lots:
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
return [l for l in self.lots if l.lot_type=='virtual'][0]
def get_basis_price(self):
price = Decimal(0)

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)
if line.mtm:
for strat in line.mtm:
values['mtm'] = line.get_mtm(values['qty'])
values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat
if values:
@@ -200,7 +200,7 @@ class ValuationBase(ModelSQL):
)
if line.mtm:
for strat in line.mtm:
values['mtm'] = line.get_mtm(values['qty'])
values['mtm'] = strat.get_mtm(values['qty'])
values['strategy'] = strat
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)
if sl_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
if values:
@@ -248,7 +248,7 @@ class ValuationBase(ModelSQL):
)
if 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
if values: