diff --git a/addons/stock_account/models/stock_quant.py b/addons/stock_account/models/stock_quant.py index a3cc36d866c..c8724bf95fb 100644 --- a/addons/stock_account/models/stock_quant.py +++ b/addons/stock_account/models/stock_quant.py @@ -20,8 +20,8 @@ class StockQuant(models.Model): 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: + quant.currency_id = quant.company_id.currency_id # If the user didn't enter a location yet while enconding a quant. if not quant.location_id: quant.value = 0 @@ -36,10 +36,10 @@ class StockQuant(models.Model): 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 + average_cost = quant.product_id.with_company(quant.company_id).value_svl / quantity quant.value = quant.quantity * average_cost else: - quant.value = quant.quantity * quant.product_id.standard_price + quant.value = quant.quantity * quant.product_id.with_company(quant.company_id).standard_price @api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): diff --git a/addons/stock_account/report/report_stock_forecasted.py b/addons/stock_account/report/report_stock_forecasted.py index 10a2dd3ebe8..496e1c5085b 100644 --- a/addons/stock_account/report/report_stock_forecasted.py +++ b/addons/stock_account/report/report_stock_forecasted.py @@ -12,9 +12,16 @@ class ReplenishmentReport(models.AbstractModel): """ Overrides to computes the valuations of the stock. """ res = super()._compute_draft_quantity_count(product_template_ids, product_variant_ids, wh_location_ids) domain = self._product_domain(product_template_ids, product_variant_ids) - svl = self.env['stock.valuation.layer'].search(domain) + company = self.env['stock.location'].browse(wh_location_ids).mapped('company_id') + svl = self.env['stock.valuation.layer'].search(domain + [('company_id', '=', company.id)]) currency = svl.currency_id or self.env.company.currency_id - value = float_repr(sum(svl.mapped('value')), precision_digits=currency.decimal_places) + quantity = sum(svl.filtered(lambda layer: layer.stock_move_id.location_dest_id.id in wh_location_ids).mapped('quantity')) + if quantity: + total_quantity = sum(svl.mapped('quantity')) + value = sum(svl.mapped('value')) * (quantity / total_quantity) + else: + value = 0 + value = float_repr(value, precision_digits=currency.decimal_places) if currency.position == 'after': value = '%s %s' % (value, currency.symbol) else: