04.01.26
This commit is contained in:
@@ -50,6 +50,8 @@ class ValuationBase(ModelSQL):
|
|||||||
amount = fields.Numeric("Amount",digits='unit')
|
amount = fields.Numeric("Amount",digits='unit')
|
||||||
mtm = fields.Numeric("Mtm",digits='unit')
|
mtm = fields.Numeric("Mtm",digits='unit')
|
||||||
lot = fields.Many2One('lot.lot',"Lot")
|
lot = fields.Many2One('lot.lot',"Lot")
|
||||||
|
base_amount = fields.Numeric("Base Amount",digits='unit')
|
||||||
|
rate = fields.Numeric("Rate", digits=(16,6))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _base_pnl(cls, *, line, lot, pnl_type, sale=None):
|
def _base_pnl(cls, *, line, lot, pnl_type, sale=None):
|
||||||
@@ -70,6 +72,8 @@ class ValuationBase(ModelSQL):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _build_basis_pnl(cls, *, line, lot, sale_line, pc, sign):
|
def _build_basis_pnl(cls, *, line, lot, sale_line, pc, sign):
|
||||||
|
Currency = Pool().get('currency.currency')
|
||||||
|
Date = Pool().get('ir.date')
|
||||||
values = cls._base_pnl(
|
values = cls._base_pnl(
|
||||||
line=line,
|
line=line,
|
||||||
lot=lot,
|
lot=lot,
|
||||||
@@ -97,22 +101,32 @@ class ValuationBase(ModelSQL):
|
|||||||
|
|
||||||
if pc.price and pc.ratio:
|
if pc.price and pc.ratio:
|
||||||
amount = round(pc.price * qty * Decimal(sign) * pc.ratio / 100, 4)
|
amount = round(pc.price * qty * Decimal(sign) * pc.ratio / 100, 4)
|
||||||
|
base_amount = amount
|
||||||
|
currency = sale_line.sale.currency.id if sale_line else line.purchase.currency.id
|
||||||
|
rate = Decimal(1)
|
||||||
|
if line.purchase.company.currency != currency:
|
||||||
|
with Transaction().set_context(date=Date.today()):
|
||||||
|
base_amount = Currency.compute(currency,amount, line.purchase.company.currency)
|
||||||
|
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), 4) if last_price else Decimal(0)
|
mtm = round(Decimal(last_price) * qty * Decimal(sign), 4) 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,
|
||||||
|
'rate': rate,
|
||||||
'mtm': round(amount - (mtm * pc.ratio / 100), 4),
|
'mtm': round(amount - (mtm * pc.ratio / 100), 4),
|
||||||
'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': sale_line.sale.currency.id if sale_line else line.purchase.currency.id,
|
'currency': currency,
|
||||||
})
|
})
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _build_simple_pnl(cls, *, line, lot, sale_line, price, state, sign, pnl_type):
|
def _build_simple_pnl(cls, *, line, lot, sale_line, price, state, sign, pnl_type):
|
||||||
|
Currency = Pool().get('currency.currency')
|
||||||
|
Date = Pool().get('ir.date')
|
||||||
values = cls._base_pnl(
|
values = cls._base_pnl(
|
||||||
line=line,
|
line=line,
|
||||||
lot=lot,
|
lot=lot,
|
||||||
@@ -121,15 +135,25 @@ class ValuationBase(ModelSQL):
|
|||||||
)
|
)
|
||||||
|
|
||||||
qty = lot.get_current_quantity_converted()
|
qty = lot.get_current_quantity_converted()
|
||||||
|
amount = round(price * qty * Decimal(sign), 4)
|
||||||
|
base_amount = amount
|
||||||
|
currency = sale_line.sale.currency.id if sale_line else line.purchase.currency.id
|
||||||
|
rate = Decimal(1)
|
||||||
|
if line.purchase.company.currency != currency:
|
||||||
|
with Transaction().set_context(date=Date.today()):
|
||||||
|
base_amount = Currency.compute(currency,amount, line.purchase.company.currency)
|
||||||
|
rate = round(amount / base_amount,6)
|
||||||
|
|
||||||
values.update({
|
values.update({
|
||||||
'price': round(price, 4),
|
'price': round(price, 4),
|
||||||
'quantity': round(qty, 5),
|
'quantity': round(qty, 5),
|
||||||
'amount': round(price * qty * Decimal(sign), 4),
|
'amount': amount,
|
||||||
|
'base_amount': base_amount,
|
||||||
|
'rate': rate,
|
||||||
'mtm': Decimal(0),
|
'mtm': Decimal(0),
|
||||||
'state': state,
|
'state': state,
|
||||||
'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': sale_line.sale.currency.id if sale_line else line.purchase.currency.id,
|
'currency': currency,
|
||||||
'counterparty': sale_line.sale.party.id if sale_line else line.purchase.party.id,
|
'counterparty': sale_line.sale.party.id if sale_line else line.purchase.party.id,
|
||||||
'product': sale_line.product.id if sale_line else line.product.id,
|
'product': sale_line.product.id if sale_line else line.product.id,
|
||||||
'reference': (
|
'reference': (
|
||||||
@@ -348,6 +372,8 @@ 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_base_amount = fields.Numeric("Base Amount",digits='r_unit')
|
||||||
|
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_lot = fields.Many2One('lot.lot',"Lot")
|
r_lot = fields.Many2One('lot.lot',"Lot")
|
||||||
|
|
||||||
@@ -378,9 +404,77 @@ 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.base_amount).as_('r_base_amount'),
|
||||||
|
Sum(val.rate).as_('r_rate'),
|
||||||
Sum(val.mtm).as_('r_mtm'),
|
Sum(val.mtm).as_('r_mtm'),
|
||||||
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])
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
class ValuationReport(ValuationBase, ModelView):
|
||||||
|
"Valuation Report"
|
||||||
|
__name__ = 'valuation.report'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def table_query(cls):
|
||||||
|
Valuation = Pool().get('valuation.valuation')
|
||||||
|
val = Valuation.__table__()
|
||||||
|
context = Transaction().context
|
||||||
|
valuation_date = context.get('valuation_date')
|
||||||
|
wh = (val.date == valuation_date)
|
||||||
|
|
||||||
|
query = val.select(
|
||||||
|
Literal(0).as_('create_uid'),
|
||||||
|
CurrentTimestamp().as_('create_date'),
|
||||||
|
Literal(None).as_('write_uid'),
|
||||||
|
Literal(None).as_('write_date'),
|
||||||
|
val.id.as_('id'),
|
||||||
|
val.purchase.as_('purchase'),
|
||||||
|
val.line.as_('line'),
|
||||||
|
val.date.as_('date'),
|
||||||
|
val.type.as_('type'),
|
||||||
|
val.reference.as_('reference'),
|
||||||
|
val.counterparty.as_('counterparty'),
|
||||||
|
val.product.as_('product'),
|
||||||
|
val.state.as_('state'),
|
||||||
|
val.price.as_('price'),
|
||||||
|
val.currency.as_('currency'),
|
||||||
|
val.quantity.as_('quantity'),
|
||||||
|
val.unit.as_('unit'),
|
||||||
|
val.amount.as_('amount'),
|
||||||
|
val.base_amount.as_('base_amount'),
|
||||||
|
val.rate.as_('rate'),
|
||||||
|
val.mtm.as_('mtm'),
|
||||||
|
val.lot.as_('lot'),
|
||||||
|
where=wh)
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
|
class ValuationReportContext(ModelView):
|
||||||
|
"Valuation Report Context"
|
||||||
|
__name__ = 'valuation.report.context'
|
||||||
|
|
||||||
|
valuation_date = fields.Date("Valuation date")
|
||||||
|
supplier = fields.Many2One('party.party',"Supplier")
|
||||||
|
client = fields.Many2One('party.party',"Client")
|
||||||
|
product = fields.Many2One('product.product',"Product")
|
||||||
|
purchase = fields.Many2One('purchase.purchase', "Purchase")
|
||||||
|
sale = fields.Many2One('sale.sale',"Sale")
|
||||||
|
state = fields.Selection([
|
||||||
|
('all', 'All'),
|
||||||
|
('open', 'Open'),
|
||||||
|
('fixed', 'Fixed'),
|
||||||
|
('hedged', 'Hedged')
|
||||||
|
], 'State')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def default_valuation_date(cls):
|
||||||
|
pool = Pool()
|
||||||
|
Date = pool.get('ir.date')
|
||||||
|
return Date.today()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def default_state(cls):
|
||||||
|
return 'all'
|
||||||
|
|||||||
@@ -20,5 +20,32 @@
|
|||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="name">valuation_tree_sequence4</field>
|
<field name="name">valuation_tree_sequence4</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="open_position_context_view_form">
|
||||||
|
<field name="model">valuation.report.context</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">valuation_context_form</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.ui.view" id="open_position_view_list">
|
||||||
|
<field name="model">valuation.report</field>
|
||||||
|
<field name="type">tree</field>
|
||||||
|
<field name="name">valuation_list</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.act_window" id="act_valuation_form">
|
||||||
|
<field name="name">Valuation</field>
|
||||||
|
<field name="res_model">valuation.report</field>
|
||||||
|
<field name="context_model">valuation.report.context</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.act_window.view" id="act_valuation_form_view">
|
||||||
|
<field name="sequence" eval="70"/>
|
||||||
|
<field name="view" ref="valuation_view_list"/>
|
||||||
|
<field name="act_window" ref="act_valuation_form"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem
|
||||||
|
parent="purchase_trade.menu_global_reporting"
|
||||||
|
sequence="120"
|
||||||
|
action="act_valuation_form"
|
||||||
|
id="menu_valuation_form"/>
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
16
modules/purchase_trade/view/valuation_context_form.xml
Normal file
16
modules/purchase_trade/view/valuation_context_form.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<form>
|
||||||
|
<label name="valuation_date"/>
|
||||||
|
<field name="valuation_date"/>
|
||||||
|
<label name="supplier"/>
|
||||||
|
<field name="supplier"/>
|
||||||
|
<label name="client"/>
|
||||||
|
<field name="client"/>
|
||||||
|
<label name="purchase"/>
|
||||||
|
<field name="purchase"/>
|
||||||
|
<label name="sale"/>
|
||||||
|
<field name="sale"/>
|
||||||
|
<label name="product"/>
|
||||||
|
<field name="product"/>
|
||||||
|
<label name="state"/>
|
||||||
|
<field name="state"/>
|
||||||
|
</form>
|
||||||
15
modules/purchase_trade/view/valuation_list.xml
Normal file
15
modules/purchase_trade/view/valuation_list.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<tree>
|
||||||
|
<field name="lot"/>
|
||||||
|
<field name="purchase"/>
|
||||||
|
<field name="sale"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="reference"/>
|
||||||
|
<field name="counterparty"/>
|
||||||
|
<field name="state"/>
|
||||||
|
<field name="price"/>
|
||||||
|
<field name="quantity" symbol="unit"/>
|
||||||
|
<field name="amount"/>
|
||||||
|
<field name="base_amount" sum="1"/>
|
||||||
|
<field name="rate"/>
|
||||||
|
<field name="mtm" optional="1" sum="1"/>
|
||||||
|
</tree>
|
||||||
Reference in New Issue
Block a user