Pnl
This commit is contained in:
@@ -1596,17 +1596,14 @@ class ValuationBase(ModelSQL):
|
||||
|
||||
@classmethod
|
||||
def create_pnl_der_from_line(cls, line):
|
||||
Date = Pool().get('ir.date')
|
||||
der_lines = []
|
||||
|
||||
for d in line.derivatives or []:
|
||||
price = Decimal(d.price_index.get_price_per_qt(
|
||||
d.price, line.unit, line.purchase.currency
|
||||
))
|
||||
|
||||
mtm_price = Decimal(d.price_index.get_price(
|
||||
Date.today(), line.unit, line.purchase.currency, True
|
||||
))
|
||||
currency = line.purchase.currency
|
||||
price, _market_price, amount = cls._derivative_pnl_values(
|
||||
d, line.unit, currency)
|
||||
base_amount, rate, base_currency = cls._base_amount_values(
|
||||
amount, currency, line.purchase.company.currency)
|
||||
|
||||
der_lines.append({
|
||||
'purchase': line.purchase.id,
|
||||
@@ -1619,28 +1616,28 @@ class ValuationBase(ModelSQL):
|
||||
'product': d.product.id,
|
||||
'state': 'fixed',
|
||||
'quantity': round(d.quantity, 5),
|
||||
'amount': round(price * d.quantity * Decimal(-1), 2),
|
||||
'mtm_price': round(mtm_price, 4),
|
||||
'mtm': round((price * d.quantity * Decimal(-1)) - (mtm_price * d.quantity * Decimal(-1)), 2),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': base_currency,
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None,
|
||||
'unit': line.unit.id,
|
||||
'currency': line.purchase.currency.id,
|
||||
'currency': currency.id,
|
||||
})
|
||||
|
||||
return der_lines
|
||||
|
||||
@classmethod
|
||||
def create_pnl_der_from_sale_line(cls, sale_line):
|
||||
Date = Pool().get('ir.date')
|
||||
der_lines = []
|
||||
|
||||
for d in sale_line.derivatives or []:
|
||||
price = Decimal(d.price_index.get_price_per_qt(
|
||||
d.price, sale_line.unit, sale_line.sale.currency
|
||||
))
|
||||
|
||||
mtm_price = Decimal(d.price_index.get_price(
|
||||
Date.today(), sale_line.unit, sale_line.sale.currency, True
|
||||
))
|
||||
currency = sale_line.sale.currency
|
||||
price, _market_price, amount = cls._derivative_pnl_values(
|
||||
d, sale_line.unit, currency)
|
||||
base_amount, rate, base_currency = cls._base_amount_values(
|
||||
amount, currency, sale_line.sale.company.currency)
|
||||
|
||||
der_lines.append({
|
||||
'sale': sale_line.sale.id,
|
||||
@@ -1653,14 +1650,31 @@ class ValuationBase(ModelSQL):
|
||||
'product': d.product.id,
|
||||
'state': 'fixed',
|
||||
'quantity': round(d.quantity, 5),
|
||||
'amount': round(price * d.quantity * Decimal(-1), 2),
|
||||
'mtm_price': round(mtm_price, 4),
|
||||
'mtm': round((price * d.quantity * Decimal(-1)) - (mtm_price * d.quantity * Decimal(-1)), 2),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': base_currency,
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None,
|
||||
'unit': sale_line.unit.id,
|
||||
'currency': sale_line.sale.currency.id,
|
||||
'currency': currency.id,
|
||||
})
|
||||
|
||||
return der_lines
|
||||
|
||||
@classmethod
|
||||
def _derivative_pnl_values(cls, derivative, unit, currency):
|
||||
Date = Pool().get('ir.date')
|
||||
entry_price = Decimal(derivative.price_index.get_price_per_qt(
|
||||
derivative.price, unit, currency))
|
||||
market_price = Decimal(derivative.price_index.get_price(
|
||||
Date.today(), unit, currency, True))
|
||||
quantity = Decimal(derivative.quantity or 0)
|
||||
direction = Decimal(1)
|
||||
if getattr(derivative, 'direction', None) == 'short':
|
||||
direction = Decimal(-1)
|
||||
amount = round((market_price - entry_price) * quantity * direction, 2)
|
||||
return round(entry_price, 4), round(market_price, 4), amount
|
||||
|
||||
@classmethod
|
||||
def generate(cls, line, valuation_type='all'):
|
||||
|
||||
Reference in New Issue
Block a user