diff --git a/modules/purchase_trade/sale.py b/modules/purchase_trade/sale.py
index 32b612f..2d75e41 100755
--- a/modules/purchase_trade/sale.py
+++ b/modules/purchase_trade/sale.py
@@ -2781,16 +2781,19 @@ class ValuationDyn(metaclass=PoolMeta):
Sum(val.quantity).as_('r_quantity'),
Max(val.unit).as_('r_unit'),
Sum(val.amount).as_('r_amount'),
+ Sum(val.amount_prev).as_('r_amount_prev'),
Sum(val.base_amount).as_('r_base_amount'),
Sum(val.rate).as_('r_rate'),
Avg(val.mtm_price).as_('r_mtm_price'),
+ Avg(val.mtm_price_prev).as_('r_mtm_price_prev'),
+ val.mtm_curve.as_('r_mtm_curve'),
Sum(val.mtm).as_('r_mtm'),
Max(val.strategy).as_('r_strategy'),
Max(val.lot).as_('r_lot'),
Max(val.sale_line).as_('r_sale_line'),
Max(val.shipment_in).as_('r_shipment_in'),
where=wh,
- group_by=[val.purchase,val.sale])
+ group_by=[val.purchase, val.sale, val.mtm_curve])
return query
diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py
index 5d17459..4ae6a9c 100644
--- a/modules/purchase_trade/tests/test_module.py
+++ b/modules/purchase_trade/tests/test_module.py
@@ -1841,6 +1841,34 @@ class PurchaseTradeTestCase(ModuleTestCase):
Valuation._value_key(base),
Valuation._value_key(regenerated))
+ def test_snapshot_identity_keeps_mtm_curves_distinct(self):
+ 'valuation snapshot identity keeps strategy curves distinct'
+ Valuation = Pool().get('valuation.valuation')
+ base = {
+ 'purchase': 1,
+ 'line': 2,
+ 'sale': None,
+ 'sale_line': None,
+ 'lot': 5,
+ 'type': 'pur. priced',
+ 'reference': 'Open',
+ 'counterparty': 6,
+ 'product': 7,
+ 'state': 'fixed',
+ 'strategy': 8,
+ 'shipment_in': None,
+ 'mtm_curve': 10,
+ }
+ other_curve = base.copy()
+ other_curve['mtm_curve'] = 20
+
+ self.assertNotEqual(
+ Valuation._value_key(base),
+ Valuation._value_key(other_curve))
+ self.assertIn(
+ ('mtm_curve', '=', 10),
+ Valuation._snapshot_identity_domain(base))
+
def test_generate_from_matched_sale_line_does_not_create_snapshot(self):
'matched sale line pnl is owned by the matched purchase line'
Valuation = Pool().get('valuation.valuation')
diff --git a/modules/purchase_trade/valuation.py b/modules/purchase_trade/valuation.py
index 31baedb..cee059a 100644
--- a/modules/purchase_trade/valuation.py
+++ b/modules/purchase_trade/valuation.py
@@ -337,6 +337,7 @@ class ValuationBase(ModelSQL):
value.get('state'),
value.get('strategy'),
value.get('shipment_in'),
+ value.get('mtm_curve'),
)
@classmethod
@@ -362,6 +363,7 @@ class ValuationBase(ModelSQL):
('state', '=', value.get('state')),
('strategy', '=', value.get('strategy')),
('shipment_in', '=', value.get('shipment_in')),
+ ('mtm_curve', '=', value.get('mtm_curve')),
]
if value.get('sale_line'):
domain.append(('sale_line', '=', value.get('sale_line')))
@@ -1508,9 +1510,12 @@ class ValuationDyn(ModelSQL,ModelView):
r_quantity = fields.Numeric("Quantity",digits='r_unit')
r_unit = fields.Many2One('product.uom',"Unit")
r_amount = fields.Numeric("Amount",digits='r_unit')
+ r_amount_prev = fields.Numeric("Amount -1", digits='r_unit')
r_base_amount = fields.Numeric("Base Amount",digits='r_unit')
r_rate = fields.Numeric("Rate",digits=(16,6))
r_mtm_price = fields.Numeric("Mtm Price",digits='r_unit')
+ r_mtm_price_prev = fields.Numeric("Mtm Price -1", digits='r_unit')
+ r_mtm_curve = fields.Many2One('price.price', "Curve")
r_mtm = fields.Numeric("Mtm",digits='r_unit')
r_strategy = fields.Many2One('mtm.strategy',"Strategy")
r_lot = fields.Many2One('lot.lot',"Lot")
@@ -1543,15 +1548,18 @@ class ValuationDyn(ModelSQL,ModelView):
Sum(val.quantity).as_('r_quantity'),
Max(val.unit).as_('r_unit'),
Sum(val.amount).as_('r_amount'),
+ Sum(val.amount_prev).as_('r_amount_prev'),
Sum(val.base_amount).as_('r_base_amount'),
Sum(val.rate).as_('r_rate'),
Avg(val.mtm_price).as_('r_mtm_price'),
+ Avg(val.mtm_price_prev).as_('r_mtm_price_prev'),
+ val.mtm_curve.as_('r_mtm_curve'),
Sum(val.mtm).as_('r_mtm'),
Max(val.strategy).as_('r_strategy'),
Max(val.lot).as_('r_lot'),
Max(val.shipment_in).as_('r_shipment_in'),
where=wh,
- group_by=[val.type,val.counterparty,val.state])
+ group_by=[val.type, val.counterparty, val.state, val.mtm_curve])
return query
diff --git a/modules/purchase_trade/view/valuation_tree_sequence4.xml b/modules/purchase_trade/view/valuation_tree_sequence4.xml
index c66c279..0070c03 100755
--- a/modules/purchase_trade/view/valuation_tree_sequence4.xml
+++ b/modules/purchase_trade/view/valuation_tree_sequence4.xml
@@ -10,9 +10,19 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
+
+
+