Skip to content
Snippets Groups Projects
Commit 3ff51daa authored by Richard deMeester's avatar Richard deMeester Committed by Arnold Moyaux
Browse files

[FIX] stock_account: Changing costing method with negative stock


Usecase to reproduce:
- Set product as FIFO and a cost of 10$
- Sell 5 units
- Modify the cost method to average

We expect the value of the stock to remain -50$.
However it went to -150$

It happens because the change of cost method is not supported
with negative quantity of stock. It's not really a huge bug because
it will be reconcile to the real value in the next in and when the
stock will be positive again but at least it gives a proper valuation
of the inventory.

opw-3100717

closes odoo/odoo#108692

Signed-off-by: default avatarArnold Moyaux (arm) <arm@odoo.com>
parent fe7cb4da
Branches
Tags
No related merge requests found
......@@ -551,7 +551,10 @@ class ProductProduct(models.Model):
if float_is_zero(product.quantity_svl, precision_rounding=product.uom_id.rounding):
# FIXME: create an empty layer to track the change?
continue
svsl_vals = product._prepare_out_svl_vals(product.quantity_svl, self.env.company)
if float_compare(product.quantity_svl, 0, precision_rounding=product.uom_id.rounding) > 0:
svsl_vals = product._prepare_out_svl_vals(product.quantity_svl, self.env.company)
else:
svsl_vals = product._prepare_in_svl_vals(abs(product.quantity_svl), product.value_svl / product.quantity_svl)
svsl_vals['description'] = description + svsl_vals.pop('rounding_adjustment', '')
svsl_vals['company_id'] = self.env.company.id
empty_stock_svl_list.append(svsl_vals)
......@@ -562,7 +565,10 @@ class ProductProduct(models.Model):
for product in self:
quantity_svl = products_orig_quantity_svl[product.id]
if quantity_svl:
svl_vals = product._prepare_in_svl_vals(quantity_svl, product.standard_price)
if float_compare(quantity_svl, 0, precision_rounding=product.uom_id.rounding) > 0:
svl_vals = product._prepare_in_svl_vals(quantity_svl, product.standard_price)
else:
svl_vals = product._prepare_out_svl_vals(abs(quantity_svl), self.env.company)
svl_vals['description'] = description
svl_vals['company_id'] = self.env.company.id
refill_stock_svl_list.append(svl_vals)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment