[IMP] stock_account: value on quant

This commit introduces back the value by location feature dropped in v11.
The feature was dropped because we implement financial fifo, thus the
value by location does not make sense for this cost method.

This commit introduces an estimation of the value by location in fifo.

Task: 1880379
This commit is contained in:
Arnold Moyaux
2019-07-12 11:37:13 +00:00
parent 7824b1f07e
commit c861edefaa
4 changed files with 80 additions and 0 deletions
+1
View File
@@ -31,6 +31,7 @@ Dashboard / Reports for Warehouse Management includes:
'views/res_config_settings_views.xml',
'data/product_data.xml',
'views/product_views.xml',
'views/stock_quant_views.xml',
'views/stock_valuation_layer_views.xml',
],
'test': [
+1
View File
@@ -10,5 +10,6 @@ from . import stock_inventory
from . import stock_location
from . import stock_move_line
from . import stock_picking
from . import stock_quant
from . import stock_valuation_layer
from . import res_config_settings
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo.tools.float_utils import float_is_zero
class StockQuant(models.Model):
_inherit = 'stock.quant'
value = fields.Monetary('Value', compute='_compute_value', groups='stock.group_stock_manager')
currency_id = fields.Many2one(related='product_id.currency_id', groups='stock.group_stock_manager')
@api.depends('quantity')
def _compute_value(self):
""" For standard and AVCO valuation, compute the current accounting
valuation of the quants by multiplying the quantity by
the standard price. Instead for FIFO, use the quantity times the
average cost (valuation layers are not manage by location so the
average cost is the same for all location and the valuation field is
a estimation more than a real value).
"""
for quant in self:
if not quant.location_id._should_be_valued() or\
(quant.owner_id and quant.owner_id != quant.company_id.partner_id):
quant.value = 0
continue
if quant.product_id.cost_method == 'fifo':
quantity = quant.product_id.quantity_svl
if float_is_zero(quantity, precision_rounding=quant.product_id.uom_id.rounding):
quant.value = 0.0
continue
average_cost = quant.product_id.value_svl / quantity
quant.value = quant.quantity * average_cost
else:
quant.value = quant.quantity * quant.product_id.standard_price
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
""" This override is done in order for the grouped list view to display the total value of
the quants inside a location. This doesn't work out of the box because `value` is a computed
field.
"""
if 'value' not in fields:
return super(StockQuant, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
res = super(StockQuant, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
for group in res:
if group.get('__domain'):
quants = self.search(group['__domain'])
group['value'] = sum(quant.value for quant in quants)
return res
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="view_stock_quant_tree_inherit">
<field name="name">stock.quant.tree.inherit</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree"></field>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_uom_id']" position="after">
<field name="currency_id" invisible="1"/>
<field name="value"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_stock_quant_tree_editable_inherit">
<field name="name">stock.quant.tree.editable.inherit</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_editable"></field>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_uom_id']" position="after">
<field name="currency_id" invisible="1"/>
<field name="value"/>
</xpath>
</field>
</record>
</odoo>