This commit is contained in:
2026-02-08 22:26:24 +01:00
parent bc5aa57319
commit 0c83fcf35e
2 changed files with 14 additions and 14 deletions

View File

@@ -91,7 +91,7 @@ class MtmStrategy(ModelSQL, ModelView):
def default_active(cls):
return True
def get_mtm(self,qty):
def get_mtm(self,line,qty):
pool = Pool()
Currency = pool.get('currency.currency')
total = Decimal(0)
@@ -106,14 +106,14 @@ class MtmStrategy(ModelSQL, ModelView):
value = Decimal(
comp.price_index.get_price(
dt,
self.purchase_line.unit,
line.unit,
self.currency,
last=scenario.use_last_price
)
)
elif comp.price_source_type == 'matrix' and comp.price_matrix:
value = self._get_matrix_price(comp, dt)
value = self._get_matrix_price(comp, line, dt)
if comp.ratio:
value *= Decimal(comp.ratio)
@@ -122,18 +122,18 @@ class MtmStrategy(ModelSQL, ModelView):
return total
def _get_matrix_price(self, comp, dt):
def _get_matrix_price(self, comp, line, dt):
MatrixLine = Pool().get('price.matrix.line')
domain = [
('matrix', '=', comp.price_matrix.id),
]
# if self.purchase_line:
# domain += [
# ('origin', '=', self.purchase_line.from_location),
# ('destination', '=', self.purchase_line.to_location),
# ]
if line:
domain += [
('origin', '=', line.purchase.from_location),
('destination', '=', line.purchase.to_location),
]
lines = MatrixLine.search(domain)
if lines:

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'] = strat.get_mtm(values['quantity'])
values['mtm'] = strat.get_mtm(line,values['quantity'])
values['strategy'] = strat
if values:
@@ -200,7 +200,7 @@ class ValuationBase(ModelSQL):
)
if line.mtm:
for strat in line.mtm:
values['mtm'] = strat.get_mtm(values['quantity'])
values['mtm'] = strat.get_mtm(line,values['quantity'])
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'] = strat.get_mtm(values['quantity'])
values['mtm'] = strat.get_mtm(sl_line,values['quantity'])
values['strategy'] = strat
if values:
@@ -248,7 +248,7 @@ class ValuationBase(ModelSQL):
)
if sl_line.mtm:
for strat in sl_line.mtm:
values['mtm'] = strat.get_mtm(values['quantity'])
values['mtm'] = strat.get_mtm(sl_line,values['quantity'])
values['strategy'] = strat
if values:
@@ -323,7 +323,7 @@ class ValuationBase(ModelSQL):
'state': sf.type,
'quantity': qty,
'amount': amount,
'mtm': strat.get_mtm(qty),
'mtm': strat.get_mtm(line,qty),
'strategy': strat,
'unit': sf.unit.id if sf.unit else line.unit.id,
'currency': sf.currency.id,