Valuation currency
This commit is contained in:
@@ -67,6 +67,7 @@ class ValuationBase(ModelSQL):
|
||||
shipment_in = fields.Many2One('stock.shipment.in', "Shipment In")
|
||||
fee = fields.Many2One('fee.fee', "Fee")
|
||||
base_amount = fields.Numeric("Base Amount",digits=(16,2))
|
||||
base_currency = fields.Many2One('currency.currency', "Base Cur")
|
||||
rate = fields.Numeric("Rate", digits=(16,6))
|
||||
|
||||
@classmethod
|
||||
@@ -136,6 +137,20 @@ class ValuationBase(ModelSQL):
|
||||
return Decimal(str(Uom.compute_qty(
|
||||
lot_unit, float(quantity), line_unit, True, factor, rate)))
|
||||
|
||||
@classmethod
|
||||
def _base_amount_values(cls, amount, currency, company_currency):
|
||||
Currency = Pool().get('currency.currency')
|
||||
Date = Pool().get('ir.date')
|
||||
base_amount = amount
|
||||
rate = Decimal(1)
|
||||
if cls._record_id(currency) != cls._record_id(company_currency):
|
||||
with Transaction().set_context(date=Date.today()):
|
||||
base_amount = Currency.compute(
|
||||
currency, amount, company_currency)
|
||||
if base_amount and amount:
|
||||
rate = round(amount / base_amount, 6)
|
||||
return base_amount, rate, cls._record_id(company_currency)
|
||||
|
||||
@classmethod
|
||||
def _purchase_lot_segments(cls, line, lot, LotQt):
|
||||
if getattr(lot, 'lot_type', None) == 'physic':
|
||||
@@ -740,6 +755,7 @@ class ValuationBase(ModelSQL):
|
||||
'quantity': round(qty, 5),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': cls._record_id(line.purchase.company.currency),
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None, #round(amount - (mtm * pc.ratio / 100), 2),
|
||||
@@ -781,6 +797,7 @@ class ValuationBase(ModelSQL):
|
||||
'quantity': round(qty, 5),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': cls._record_id(company_currency),
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': Decimal(0),
|
||||
@@ -946,6 +963,7 @@ class ValuationBase(ModelSQL):
|
||||
'quantity': round(qty, 5),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': cls._record_id(sale_line.sale.company.currency),
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None,
|
||||
@@ -981,6 +999,7 @@ class ValuationBase(ModelSQL):
|
||||
'quantity': round(qty, 5),
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': cls._record_id(company_currency),
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': Decimal(0),
|
||||
@@ -1244,6 +1263,8 @@ class ValuationBase(ModelSQL):
|
||||
with Transaction().set_context(date=Date.today()):
|
||||
price = Currency.compute(
|
||||
sf.currency, price, line.purchase.currency)
|
||||
base_amount, rate, base_currency = cls._base_amount_values(
|
||||
amount, sf.currency, line.purchase.company.currency)
|
||||
fee_lines.append({
|
||||
'lot': lot.id,
|
||||
'sale': matched_sale_line.sale.id if matched_sale_line else None,
|
||||
@@ -1265,6 +1286,9 @@ class ValuationBase(ModelSQL):
|
||||
'state': sf.type,
|
||||
'quantity': qty,
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': base_currency,
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None,
|
||||
'strategy': None,
|
||||
@@ -1309,6 +1333,8 @@ class ValuationBase(ModelSQL):
|
||||
with Transaction().set_context(date=Date.today()):
|
||||
price = Currency.compute(
|
||||
sf.currency, price, sale_line.sale.currency)
|
||||
base_amount, rate, base_currency = cls._base_amount_values(
|
||||
amount, sf.currency, sale_line.sale.company.currency)
|
||||
fee_lines.append({
|
||||
'lot': lot.id,
|
||||
'sale': sale_line.sale.id,
|
||||
@@ -1327,6 +1353,9 @@ class ValuationBase(ModelSQL):
|
||||
'state': sf.type,
|
||||
'quantity': qty,
|
||||
'amount': amount,
|
||||
'base_amount': base_amount,
|
||||
'base_currency': base_currency,
|
||||
'rate': rate,
|
||||
'mtm_price': None,
|
||||
'mtm': None,
|
||||
'strategy': None,
|
||||
@@ -1536,6 +1565,7 @@ class ValuationDyn(ModelSQL,ModelView):
|
||||
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_currency = fields.Many2One('currency.currency', "Base Cur")
|
||||
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')
|
||||
@@ -1574,6 +1604,7 @@ class ValuationDyn(ModelSQL,ModelView):
|
||||
Sum(val.amount).as_('r_amount'),
|
||||
Sum(val.amount_prev).as_('r_amount_prev'),
|
||||
Sum(val.base_amount).as_('r_base_amount'),
|
||||
Max(val.base_currency).as_('r_base_currency'),
|
||||
Sum(val.rate).as_('r_rate'),
|
||||
Avg(val.mtm_price).as_('r_mtm_price'),
|
||||
Avg(val.mtm_price_prev).as_('r_mtm_price_prev'),
|
||||
@@ -1631,6 +1662,7 @@ class ValuationReport(ValuationBase, ModelView):
|
||||
val.amount.as_('amount'),
|
||||
val.amount_prev.as_('amount_prev'),
|
||||
val.base_amount.as_('base_amount'),
|
||||
val.base_currency.as_('base_currency'),
|
||||
val.rate.as_('rate'),
|
||||
val.mtm_price.as_('mtm_price'),
|
||||
val.mtm_price_prev.as_('mtm_price_prev'),
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
sum="1"
|
||||
sum_previous="amount_prev"
|
||||
sum_variation="1"/>
|
||||
<field name="currency"/>
|
||||
<field name="amount_prev" optional="1"/>
|
||||
<field name="base_amount" sum="1"/>
|
||||
<field name="base_currency"/>
|
||||
<field name="rate"/>
|
||||
<field name="strategy"/>
|
||||
<field name="mtm_curve"/>
|
||||
|
||||
@@ -17,7 +17,11 @@ this repository contains the full copyright notices and license terms. -->
|
||||
sum="1"
|
||||
sum_previous="amount_prev"
|
||||
sum_variation="1"/>
|
||||
<field name="currency"/>
|
||||
<field name="amount_prev" optional="1"/>
|
||||
<field name="base_amount" sum="1"/>
|
||||
<field name="base_currency"/>
|
||||
<field name="rate"/>
|
||||
<field name="strategy"/>
|
||||
<field name="mtm_curve"/>
|
||||
<field name="mtm_price"
|
||||
|
||||
Reference in New Issue
Block a user