[FIX] stock_account: total quantity can be zero
Follow-up of https://github.com/odoo/odoo/pull/64942 Explanation: When computing the total quantity, summing negative and positive values can sometimes lead to zero even if the scoped quantity is not zero. E.g.: Warehouse 1 has 10 items and Warehouse 2 has -10 items. Scoping on Warehouse 1 results in 10 items but the total quantity is 0. This commit also takes into account float precision. Inspired by: https://github.com/odoo/odoo/blob/d9b409247303c6b165a7df381169f2480a19900f/addons/stock_account/models/stock_quant.py#L36-L38 closes odoo/odoo#65661 X-original-commit: 3547b15cb362f73c60354070da5e49ffa674e432 Signed-off-by: backspac <backspac@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
from odoo.tools.float_utils import float_repr
|
||||
from odoo.tools.float_utils import float_is_zero, float_repr
|
||||
|
||||
|
||||
class ReplenishmentReport(models.AbstractModel):
|
||||
@@ -15,9 +15,10 @@ class ReplenishmentReport(models.AbstractModel):
|
||||
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
|
||||
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'))
|
||||
total_quantity = sum(svl.mapped('quantity'))
|
||||
# Because we can have negative quantities, `total_quantity` may be equal to zero even if the warehouse's `quantity` is positive.
|
||||
if svl and not float_is_zero(total_quantity, precision_rounding=svl.product_id.uom_id.rounding):
|
||||
quantity = sum(svl.filtered(lambda layer: layer.stock_move_id.location_dest_id.id in wh_location_ids).mapped('quantity'))
|
||||
value = sum(svl.mapped('value')) * (quantity / total_quantity)
|
||||
else:
|
||||
value = 0
|
||||
|
||||
Reference in New Issue
Block a user