Mtm bug
This commit is contained in:
@@ -2781,16 +2781,19 @@ class ValuationDyn(metaclass=PoolMeta):
|
|||||||
Sum(val.quantity).as_('r_quantity'),
|
Sum(val.quantity).as_('r_quantity'),
|
||||||
Max(val.unit).as_('r_unit'),
|
Max(val.unit).as_('r_unit'),
|
||||||
Sum(val.amount).as_('r_amount'),
|
Sum(val.amount).as_('r_amount'),
|
||||||
|
Sum(val.amount_prev).as_('r_amount_prev'),
|
||||||
Sum(val.base_amount).as_('r_base_amount'),
|
Sum(val.base_amount).as_('r_base_amount'),
|
||||||
Sum(val.rate).as_('r_rate'),
|
Sum(val.rate).as_('r_rate'),
|
||||||
Avg(val.mtm_price).as_('r_mtm_price'),
|
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'),
|
Sum(val.mtm).as_('r_mtm'),
|
||||||
Max(val.strategy).as_('r_strategy'),
|
Max(val.strategy).as_('r_strategy'),
|
||||||
Max(val.lot).as_('r_lot'),
|
Max(val.lot).as_('r_lot'),
|
||||||
Max(val.sale_line).as_('r_sale_line'),
|
Max(val.sale_line).as_('r_sale_line'),
|
||||||
Max(val.shipment_in).as_('r_shipment_in'),
|
Max(val.shipment_in).as_('r_shipment_in'),
|
||||||
where=wh,
|
where=wh,
|
||||||
group_by=[val.purchase,val.sale])
|
group_by=[val.purchase, val.sale, val.mtm_curve])
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|||||||
@@ -1841,6 +1841,34 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
Valuation._value_key(base),
|
Valuation._value_key(base),
|
||||||
Valuation._value_key(regenerated))
|
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):
|
def test_generate_from_matched_sale_line_does_not_create_snapshot(self):
|
||||||
'matched sale line pnl is owned by the matched purchase line'
|
'matched sale line pnl is owned by the matched purchase line'
|
||||||
Valuation = Pool().get('valuation.valuation')
|
Valuation = Pool().get('valuation.valuation')
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ class ValuationBase(ModelSQL):
|
|||||||
value.get('state'),
|
value.get('state'),
|
||||||
value.get('strategy'),
|
value.get('strategy'),
|
||||||
value.get('shipment_in'),
|
value.get('shipment_in'),
|
||||||
|
value.get('mtm_curve'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -362,6 +363,7 @@ class ValuationBase(ModelSQL):
|
|||||||
('state', '=', value.get('state')),
|
('state', '=', value.get('state')),
|
||||||
('strategy', '=', value.get('strategy')),
|
('strategy', '=', value.get('strategy')),
|
||||||
('shipment_in', '=', value.get('shipment_in')),
|
('shipment_in', '=', value.get('shipment_in')),
|
||||||
|
('mtm_curve', '=', value.get('mtm_curve')),
|
||||||
]
|
]
|
||||||
if value.get('sale_line'):
|
if value.get('sale_line'):
|
||||||
domain.append(('sale_line', '=', 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_quantity = fields.Numeric("Quantity",digits='r_unit')
|
||||||
r_unit = fields.Many2One('product.uom',"Unit")
|
r_unit = fields.Many2One('product.uom',"Unit")
|
||||||
r_amount = fields.Numeric("Amount",digits='r_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_base_amount = fields.Numeric("Base Amount",digits='r_unit')
|
||||||
r_rate = fields.Numeric("Rate",digits=(16,6))
|
r_rate = fields.Numeric("Rate",digits=(16,6))
|
||||||
r_mtm_price = fields.Numeric("Mtm Price",digits='r_unit')
|
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_mtm = fields.Numeric("Mtm",digits='r_unit')
|
||||||
r_strategy = fields.Many2One('mtm.strategy',"Strategy")
|
r_strategy = fields.Many2One('mtm.strategy',"Strategy")
|
||||||
r_lot = fields.Many2One('lot.lot',"Lot")
|
r_lot = fields.Many2One('lot.lot',"Lot")
|
||||||
@@ -1543,15 +1548,18 @@ class ValuationDyn(ModelSQL,ModelView):
|
|||||||
Sum(val.quantity).as_('r_quantity'),
|
Sum(val.quantity).as_('r_quantity'),
|
||||||
Max(val.unit).as_('r_unit'),
|
Max(val.unit).as_('r_unit'),
|
||||||
Sum(val.amount).as_('r_amount'),
|
Sum(val.amount).as_('r_amount'),
|
||||||
|
Sum(val.amount_prev).as_('r_amount_prev'),
|
||||||
Sum(val.base_amount).as_('r_base_amount'),
|
Sum(val.base_amount).as_('r_base_amount'),
|
||||||
Sum(val.rate).as_('r_rate'),
|
Sum(val.rate).as_('r_rate'),
|
||||||
Avg(val.mtm_price).as_('r_mtm_price'),
|
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'),
|
Sum(val.mtm).as_('r_mtm'),
|
||||||
Max(val.strategy).as_('r_strategy'),
|
Max(val.strategy).as_('r_strategy'),
|
||||||
Max(val.lot).as_('r_lot'),
|
Max(val.lot).as_('r_lot'),
|
||||||
Max(val.shipment_in).as_('r_shipment_in'),
|
Max(val.shipment_in).as_('r_shipment_in'),
|
||||||
where=wh,
|
where=wh,
|
||||||
group_by=[val.type,val.counterparty,val.state])
|
group_by=[val.type, val.counterparty, val.state, val.mtm_curve])
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,19 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<field name="r_state"/>
|
<field name="r_state"/>
|
||||||
<field name="r_price"/>
|
<field name="r_price"/>
|
||||||
<field name="r_quantity" symbol="r_unit"/>
|
<field name="r_quantity" symbol="r_unit"/>
|
||||||
<field name="r_amount" sum="1"/>
|
<field name="r_amount"
|
||||||
|
sum="1"
|
||||||
|
sum_previous="r_amount_prev"
|
||||||
|
sum_variation="1"/>
|
||||||
|
<field name="r_amount_prev" optional="1"/>
|
||||||
<field name="r_strategy"/>
|
<field name="r_strategy"/>
|
||||||
<field name="r_mtm_price"/>
|
<field name="r_mtm_curve"/>
|
||||||
|
<field name="r_mtm_price"
|
||||||
|
widget="variation"
|
||||||
|
variation_previous="r_mtm_price_prev"
|
||||||
|
variation_group_by="r_mtm_curve"
|
||||||
|
variation_summary="1"/>
|
||||||
|
<field name="r_mtm_price_prev" optional="1"/>
|
||||||
<field name="r_mtm" optional="0" sum="1"/>
|
<field name="r_mtm" optional="0" sum="1"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user