From 0c83fcf35ea6b31750869c29694ad6c2f0198158 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sun, 8 Feb 2026 22:26:24 +0100 Subject: [PATCH] 08.02.26 --- modules/purchase_trade/pricing.py | 18 +++++++++--------- modules/purchase_trade/valuation.py | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/purchase_trade/pricing.py b/modules/purchase_trade/pricing.py index fe5e5a4..d58c910 100755 --- a/modules/purchase_trade/pricing.py +++ b/modules/purchase_trade/pricing.py @@ -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: diff --git a/modules/purchase_trade/valuation.py b/modules/purchase_trade/valuation.py index e767c80..6a39345 100644 --- a/modules/purchase_trade/valuation.py +++ b/modules/purchase_trade/valuation.py @@ -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,