08.02.26
This commit is contained in:
@@ -49,6 +49,7 @@ class ValuationBase(ModelSQL):
|
|||||||
unit = fields.Many2One('product.uom',"Unit")
|
unit = fields.Many2One('product.uom',"Unit")
|
||||||
amount = fields.Numeric("Amount",digits=(16,2))
|
amount = fields.Numeric("Amount",digits=(16,2))
|
||||||
mtm = fields.Numeric("Mtm",digits=(16,2))
|
mtm = fields.Numeric("Mtm",digits=(16,2))
|
||||||
|
strategy = fields.Many2One('mtm.strategy',"Strategy")
|
||||||
lot = fields.Many2One('lot.lot',"Lot")
|
lot = fields.Many2One('lot.lot',"Lot")
|
||||||
base_amount = fields.Numeric("Base Amount",digits=(16,2))
|
base_amount = fields.Numeric("Base Amount",digits=(16,2))
|
||||||
rate = fields.Numeric("Rate", digits=(16,6))
|
rate = fields.Numeric("Rate", digits=(16,6))
|
||||||
@@ -109,14 +110,13 @@ class ValuationBase(ModelSQL):
|
|||||||
base_amount = Currency.compute(currency,amount, line.purchase.company.currency)
|
base_amount = Currency.compute(currency,amount, line.purchase.company.currency)
|
||||||
rate = round(amount / base_amount,6)
|
rate = round(amount / base_amount,6)
|
||||||
last_price = pc.get_last_price()
|
last_price = pc.get_last_price()
|
||||||
mtm = round(Decimal(last_price) * qty * Decimal(sign), 2) if last_price else Decimal(0)
|
# mtm = round(Decimal(last_price) * qty * Decimal(sign), 2) if last_price else Decimal(0)
|
||||||
|
|
||||||
values.update({
|
values.update({
|
||||||
'quantity': round(qty, 5),
|
'quantity': round(qty, 5),
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'base_amount': base_amount,
|
'base_amount': base_amount,
|
||||||
'rate': rate,
|
'rate': rate,
|
||||||
'mtm': round(amount - (mtm * pc.ratio / 100), 2),
|
'mtm': None #round(amount - (mtm * pc.ratio / 100), 2),
|
||||||
'unit': sale_line.unit.id if sale_line else line.unit.id,
|
'unit': sale_line.unit.id if sale_line else line.unit.id,
|
||||||
'currency': currency,
|
'currency': currency,
|
||||||
})
|
})
|
||||||
@@ -177,12 +177,19 @@ class ValuationBase(ModelSQL):
|
|||||||
if line.price_type == 'basis':
|
if line.price_type == 'basis':
|
||||||
for pc in line.price_summary or []:
|
for pc in line.price_summary or []:
|
||||||
values = cls._build_basis_pnl(line=line, lot=lot, sale_line=None, pc=pc, sign=-1)
|
values = cls._build_basis_pnl(line=line, lot=lot, sale_line=None, pc=pc, sign=-1)
|
||||||
if values:
|
if line.mtm:
|
||||||
price_lines.append(values)
|
for strat in line.mtm:
|
||||||
|
values['mtm'] = line.get_mtm(values['qty'])
|
||||||
|
values['strategy'] = strat.name
|
||||||
|
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
else:
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
|
||||||
elif line.price_type in ('priced', 'efp') and lot.lot_price:
|
elif line.price_type in ('priced', 'efp') and lot.lot_price:
|
||||||
price_lines.append(
|
values = cls._build_simple_pnl(
|
||||||
cls._build_simple_pnl(
|
|
||||||
line=line,
|
line=line,
|
||||||
lot=lot,
|
lot=lot,
|
||||||
sale_line=None,
|
sale_line=None,
|
||||||
@@ -191,7 +198,16 @@ class ValuationBase(ModelSQL):
|
|||||||
sign=-1,
|
sign=-1,
|
||||||
pnl_type=f'pur. {line.price_type}'
|
pnl_type=f'pur. {line.price_type}'
|
||||||
)
|
)
|
||||||
)
|
if line.mtm:
|
||||||
|
for strat in line.mtm:
|
||||||
|
values['mtm'] = line.get_mtm(values['qty'])
|
||||||
|
values['strategy'] = strat.name
|
||||||
|
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
else:
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
|
||||||
sale_lots = [lot] if lot.sale_line else [
|
sale_lots = [lot] if lot.sale_line else [
|
||||||
lqt.lot_s for lqt in LotQt.search([
|
lqt.lot_s for lqt in LotQt.search([
|
||||||
@@ -209,12 +225,19 @@ class ValuationBase(ModelSQL):
|
|||||||
if sl_line.price_type == 'basis':
|
if sl_line.price_type == 'basis':
|
||||||
for pc in sl_line.price_summary or []:
|
for pc in sl_line.price_summary or []:
|
||||||
values = cls._build_basis_pnl(line=line, lot=sl, sale_line=sl_line, pc=pc, sign=+1)
|
values = cls._build_basis_pnl(line=line, lot=sl, sale_line=sl_line, pc=pc, sign=+1)
|
||||||
if values:
|
if sl_line.mtm:
|
||||||
price_lines.append(values)
|
for strat in line.mtm:
|
||||||
|
values['mtm'] = sl_line.get_mtm(values['qty'])
|
||||||
|
values['strategy'] = strat.name
|
||||||
|
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
else:
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
|
||||||
elif sl_line.price_type in ('priced', 'efp'):
|
elif sl_line.price_type in ('priced', 'efp'):
|
||||||
price_lines.append(
|
values = cls._build_simple_pnl(
|
||||||
cls._build_simple_pnl(
|
|
||||||
line=line,
|
line=line,
|
||||||
lot=sl,
|
lot=sl,
|
||||||
sale_line=sl_line,
|
sale_line=sl_line,
|
||||||
@@ -223,7 +246,16 @@ class ValuationBase(ModelSQL):
|
|||||||
sign=+1,
|
sign=+1,
|
||||||
pnl_type=f'sale {sl_line.price_type}'
|
pnl_type=f'sale {sl_line.price_type}'
|
||||||
)
|
)
|
||||||
)
|
if sl_line.mtm:
|
||||||
|
for strat in sl_line.mtm:
|
||||||
|
values['mtm'] = sl_line.get_mtm(values['qty'])
|
||||||
|
values['strategy'] = strat.name
|
||||||
|
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
else:
|
||||||
|
if values:
|
||||||
|
price_lines.append(values)
|
||||||
|
|
||||||
return price_lines
|
return price_lines
|
||||||
|
|
||||||
@@ -270,29 +302,56 @@ class ValuationBase(ModelSQL):
|
|||||||
if sf.currency != line.purchase.currency:
|
if sf.currency != line.purchase.currency:
|
||||||
with Transaction().set_context(date=Date.today()):
|
with Transaction().set_context(date=Date.today()):
|
||||||
price = Currency.compute(sf.currency, price, line.purchase.currency)
|
price = Currency.compute(sf.currency, price, line.purchase.currency)
|
||||||
|
if line.mtm:
|
||||||
fee_lines.append({
|
for strat in line.mtm:
|
||||||
'lot': lot.id,
|
qty = round(lot.get_current_quantity_converted(), 5)
|
||||||
'sale': lot.sale_line.sale.id if lot.sale_line else None,
|
fee_lines.append({
|
||||||
'purchase': line.purchase.id,
|
'lot': lot.id,
|
||||||
'line': line.id,
|
'sale': lot.sale_line.sale.id if lot.sale_line else None,
|
||||||
'type': (
|
'purchase': line.purchase.id,
|
||||||
'shipment fee' if sf.shipment_in
|
'line': line.id,
|
||||||
else 'sale fee' if sf.sale_line
|
'type': (
|
||||||
else 'pur. fee'
|
'shipment fee' if sf.shipment_in
|
||||||
),
|
else 'sale fee' if sf.sale_line
|
||||||
'date': Date.today(),
|
else 'pur. fee'
|
||||||
'price': price,
|
),
|
||||||
'counterparty': sf.supplier.id,
|
'date': Date.today(),
|
||||||
'reference': f"{sf.product.name}/{'Physic' if lot.lot_type == 'physic' else 'Open'}",
|
'price': price,
|
||||||
'product': sf.product.id,
|
'counterparty': sf.supplier.id,
|
||||||
'state': sf.type,
|
'reference': f"{sf.product.name}/{'Physic' if lot.lot_type == 'physic' else 'Open'}",
|
||||||
'quantity': round(lot.get_current_quantity_converted(), 5),
|
'product': sf.product.id,
|
||||||
'amount': amount,
|
'state': sf.type,
|
||||||
'mtm': Decimal(0),
|
'quantity': qty,
|
||||||
'unit': sf.unit.id if sf.unit else line.unit.id,
|
'amount': amount,
|
||||||
'currency': sf.currency.id,
|
'mtm': strat.get_mtm(qty),
|
||||||
})
|
'strategy': strat,
|
||||||
|
'unit': sf.unit.id if sf.unit else line.unit.id,
|
||||||
|
'currency': sf.currency.id,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
fee_lines.append({
|
||||||
|
'lot': lot.id,
|
||||||
|
'sale': lot.sale_line.sale.id if lot.sale_line else None,
|
||||||
|
'purchase': line.purchase.id,
|
||||||
|
'line': line.id,
|
||||||
|
'type': (
|
||||||
|
'shipment fee' if sf.shipment_in
|
||||||
|
else 'sale fee' if sf.sale_line
|
||||||
|
else 'pur. fee'
|
||||||
|
),
|
||||||
|
'date': Date.today(),
|
||||||
|
'price': price,
|
||||||
|
'counterparty': sf.supplier.id,
|
||||||
|
'reference': f"{sf.product.name}/{'Physic' if lot.lot_type == 'physic' else 'Open'}",
|
||||||
|
'product': sf.product.id,
|
||||||
|
'state': sf.type,
|
||||||
|
'quantity': qty,
|
||||||
|
'amount': amount,
|
||||||
|
'mtm': Decimal(0),
|
||||||
|
'strategy': None,
|
||||||
|
'unit': sf.unit.id if sf.unit else line.unit.id,
|
||||||
|
'currency': sf.currency.id,
|
||||||
|
})
|
||||||
|
|
||||||
return fee_lines
|
return fee_lines
|
||||||
|
|
||||||
@@ -427,6 +486,7 @@ class ValuationDyn(ModelSQL,ModelView):
|
|||||||
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 = fields.Numeric("Mtm",digits='r_unit')
|
r_mtm = fields.Numeric("Mtm",digits='r_unit')
|
||||||
|
r_strategy = fields.Many2One('mtm.strategy',"Strategy")
|
||||||
r_lot = fields.Many2One('lot.lot',"Lot")
|
r_lot = fields.Many2One('lot.lot',"Lot")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -459,6 +519,7 @@ class ValuationDyn(ModelSQL,ModelView):
|
|||||||
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'),
|
||||||
Sum(val.mtm).as_('r_mtm'),
|
Sum(val.mtm).as_('r_mtm'),
|
||||||
|
Max(val.strategy).as_('r_strategy'),
|
||||||
Max(val.lot).as_('r_lot'),
|
Max(val.lot).as_('r_lot'),
|
||||||
where=wh,
|
where=wh,
|
||||||
group_by=[val.type,val.counterparty,val.state])
|
group_by=[val.type,val.counterparty,val.state])
|
||||||
@@ -475,8 +536,11 @@ class ValuationReport(ValuationBase, ModelView):
|
|||||||
val = Valuation.__table__()
|
val = Valuation.__table__()
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
valuation_date = context.get('valuation_date')
|
valuation_date = context.get('valuation_date')
|
||||||
|
strategy = context.get('strategy')
|
||||||
wh = (val.date == valuation_date)
|
wh = (val.date == valuation_date)
|
||||||
|
if strategy:
|
||||||
|
wh &= (val.strategy == strategy)
|
||||||
|
|
||||||
query = val.select(
|
query = val.select(
|
||||||
Literal(0).as_('create_uid'),
|
Literal(0).as_('create_uid'),
|
||||||
CurrentTimestamp().as_('create_date'),
|
CurrentTimestamp().as_('create_date'),
|
||||||
@@ -501,6 +565,7 @@ class ValuationReport(ValuationBase, ModelView):
|
|||||||
val.base_amount.as_('base_amount'),
|
val.base_amount.as_('base_amount'),
|
||||||
val.rate.as_('rate'),
|
val.rate.as_('rate'),
|
||||||
val.mtm.as_('mtm'),
|
val.mtm.as_('mtm'),
|
||||||
|
val.strategy.as_('strategy'),
|
||||||
val.lot.as_('lot'),
|
val.lot.as_('lot'),
|
||||||
where=wh)
|
where=wh)
|
||||||
|
|
||||||
@@ -522,6 +587,7 @@ class ValuationReportContext(ModelView):
|
|||||||
('fixed', 'Fixed'),
|
('fixed', 'Fixed'),
|
||||||
('hedged', 'Hedged')
|
('hedged', 'Hedged')
|
||||||
], 'State')
|
], 'State')
|
||||||
|
strategy = fields.Many2One('mtm.strategy')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default_valuation_date(cls):
|
def default_valuation_date(cls):
|
||||||
|
|||||||
@@ -13,4 +13,6 @@
|
|||||||
<field name="product"/>
|
<field name="product"/>
|
||||||
<label name="state"/>
|
<label name="state"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
|
<label name="strategy"/>
|
||||||
|
<field name="strategy"/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<field name="price"/>
|
<field name="price"/>
|
||||||
<field name="quantity" symbol="unit"/>
|
<field name="quantity" symbol="unit"/>
|
||||||
<field name="amount" sum="1"/>
|
<field name="amount" sum="1"/>
|
||||||
<field name="mtm" optional="1" sum="1"/>
|
<field name="strategy"/>
|
||||||
|
<field name="mtm" optional="0" sum="1"/>
|
||||||
</tree>
|
</tree>
|
||||||
@@ -10,6 +10,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<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"/>
|
||||||
<field name="r_mtm" optional="1" sum="1"/>
|
<field name="strategy"/>
|
||||||
|
<field name="r_mtm" optional="0" sum="1"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user