Mtm new
This commit is contained in:
@@ -21,7 +21,10 @@ PHYSICAL_VALUATION_TYPES = [
|
||||
'market',
|
||||
]
|
||||
DERIVATIVE_VALUATION_TYPES = ['derivative']
|
||||
ALL_VALUATION_TYPES = PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES
|
||||
MTM_VALUATION_TYPES = ['mtm']
|
||||
ALL_VALUATION_TYPES = (
|
||||
PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES
|
||||
+ MTM_VALUATION_TYPES)
|
||||
|
||||
|
||||
class CTRMValuationContextMixin:
|
||||
@@ -249,7 +252,8 @@ class CTRMNetPosition(ModelSQL, ModelView):
|
||||
|
||||
context = Transaction().context
|
||||
where = val.type.in_(
|
||||
PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES)
|
||||
PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES
|
||||
+ MTM_VALUATION_TYPES)
|
||||
if context.get('date'):
|
||||
where &= val.date == context['date']
|
||||
if context.get('product'):
|
||||
@@ -268,14 +272,17 @@ class CTRMNetPosition(ModelSQL, ModelView):
|
||||
where &= val.state == context['state']
|
||||
|
||||
is_derivative = val.type.in_(DERIVATIVE_VALUATION_TYPES)
|
||||
is_mtm = val.type.in_(MTM_VALUATION_TYPES)
|
||||
physical_quantity = Case(
|
||||
(is_derivative, 0), else_=Coalesce(val.quantity, 0))
|
||||
(is_derivative | is_mtm, 0), else_=Coalesce(val.quantity, 0))
|
||||
derivative_quantity = Case(
|
||||
(is_derivative, Coalesce(val.quantity, 0)), else_=0)
|
||||
physical_amount = Case(
|
||||
(is_derivative, 0), else_=Coalesce(val.amount, 0))
|
||||
(is_derivative | is_mtm, 0), else_=Coalesce(val.amount, 0))
|
||||
derivative_amount = Case(
|
||||
(is_derivative, Coalesce(val.amount, 0)), else_=0)
|
||||
net_quantity = Case(
|
||||
(is_mtm, 0), else_=Coalesce(val.quantity, 0))
|
||||
|
||||
group_by = [
|
||||
val.date,
|
||||
@@ -302,7 +309,7 @@ class CTRMNetPosition(ModelSQL, ModelView):
|
||||
val.strategy.as_('strategy'),
|
||||
Sum(physical_quantity).as_('physical_quantity'),
|
||||
Sum(derivative_quantity).as_('derivative_quantity'),
|
||||
Sum(Coalesce(val.quantity, 0)).as_('net_quantity'),
|
||||
Sum(net_quantity).as_('net_quantity'),
|
||||
Sum(physical_amount).as_('physical_amount'),
|
||||
Sum(derivative_amount).as_('derivative_amount'),
|
||||
Sum(Coalesce(val.amount, 0)).as_('net_amount'),
|
||||
@@ -396,7 +403,8 @@ class CTRMRealizedPnl(ModelSQL, ModelView):
|
||||
context = Transaction().context
|
||||
realization = context.get(
|
||||
'realization', 'purchase_and_sale_invoiced')
|
||||
where = val.type.in_(ALL_VALUATION_TYPES)
|
||||
where = val.type.in_(
|
||||
PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES)
|
||||
if context.get('date'):
|
||||
where &= val.date == context['date']
|
||||
if context.get('product'):
|
||||
@@ -487,6 +495,7 @@ class CTRMMtmPnl(ModelSQL, ModelView):
|
||||
('sale fee', 'Sale fee'),
|
||||
('shipment fee', 'Shipment fee'),
|
||||
('market', 'Market'),
|
||||
('mtm', 'Mtm'),
|
||||
('derivative', 'Derivative'),
|
||||
], "Type")
|
||||
reference = fields.Char("Reference")
|
||||
@@ -610,8 +619,10 @@ class CTRMPnlExplain(ModelSQL, ModelView):
|
||||
'shipment fee',
|
||||
])
|
||||
is_derivative = val.type.in_(DERIVATIVE_VALUATION_TYPES)
|
||||
is_mtm = val.type.in_(MTM_VALUATION_TYPES)
|
||||
physical_pnl = Case(
|
||||
(is_fee | is_derivative, 0), else_=Coalesce(val.amount, 0))
|
||||
(is_fee | is_derivative | is_mtm, 0),
|
||||
else_=Coalesce(val.amount, 0))
|
||||
fee_pnl = Case((is_fee, Coalesce(val.amount, 0)), else_=0)
|
||||
derivative_pnl = Case(
|
||||
(is_derivative, Coalesce(val.amount, 0)), else_=0)
|
||||
@@ -737,7 +748,9 @@ class CTRMPnlDimension(ModelSQL, ModelView):
|
||||
val.unit.as_('unit'),
|
||||
val.state.as_('state'),
|
||||
val.strategy.as_('strategy'),
|
||||
Sum(Coalesce(val.quantity, 0)).as_('quantity'),
|
||||
Sum(Case(
|
||||
(val.type.in_(MTM_VALUATION_TYPES), 0),
|
||||
else_=Coalesce(val.quantity, 0))).as_('quantity'),
|
||||
Sum(Coalesce(val.amount, 0)).as_('amount'),
|
||||
Sum(Coalesce(val.mtm, 0)).as_('mtm'),
|
||||
Sum(Coalesce(val.mtm, 0) - Coalesce(val.amount, 0)).as_(
|
||||
@@ -1613,7 +1626,8 @@ class CTRMAccruals(ModelSQL, ModelView):
|
||||
else_='physical')
|
||||
context = Transaction().context
|
||||
where = (
|
||||
val.type.in_(ALL_VALUATION_TYPES)
|
||||
val.type.in_(
|
||||
PHYSICAL_VALUATION_TYPES + DERIVATIVE_VALUATION_TYPES)
|
||||
& ((val.lot == Null)
|
||||
| ((lot.invoice_line == Null)
|
||||
& (lot.sale_invoice_line == Null))))
|
||||
|
||||
Reference in New Issue
Block a user