- Create 2 companies A & B, with different currencies - Create a product in company B Set the company on the product Automated valuation - Receive some stock in company B - Switch to company A, and keep B available - Go to Inventory > Reporting > Inventory Report The currency on the product is the currency of the product company instead of the currency of the current company. The value is computed in the current company currency: https://github.com/odoo/odoo/blob/bc3d1f2dc408fa91d42743d6a7063042e0f6c42b/addons/stock_account/models/product.py#L115 The currency should be consistent. opw-2278751 closes odoo/odoo#53426 X-original-commit: 8aa952d18acca5a0ac3b32579e812158e641c13c Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
58 lines
2.7 KiB
Python
58 lines
2.7 KiB
Python
# -*- 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('res.currency', compute='_compute_value', groups='stock.group_stock_manager')
|
|
|
|
@api.depends('company_id', 'location_id', 'owner_id', 'product_id', '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).
|
|
"""
|
|
self.currency_id = self.env.company.currency_id
|
|
for quant in self:
|
|
# If the user didn't enter a location yet while enconding a quant.
|
|
if not quant.location_id:
|
|
quant.value = 0
|
|
return
|
|
|
|
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
|