summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2018-05-16 13:23:00 +0200
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2018-05-16 14:21:15 +0200
commit491243d1caa46b75a08a656a0049e79fd7597258 (patch)
treec0378df19f6130544159a9161613508dc6f64ebc
parentcdabb9d74c93bca30a6a129bb9c6774e4c0212e8 (diff)
[FIX] stock_account: partial reception with avg cost
- Create a product where the associated product category has Costing Method "Average Cost (AVCO)" - Create a PO. Order 1 unit at $1000. - Receive that unit. (System now has 1 unit at $1000). - Create another PO. Order 3 units at $500 each. - Receive only 1 unit and don’t create any back order. System has 2 units @ $625, instead of $750. The quantity computed should take into account the quantity actually done. opw-1843998
-rw-r--r--addons/stock_account/models/stock.py8
-rw-r--r--addons/stock_account/tests/test_stockvaluation.py33
2 files changed, 38 insertions, 3 deletions
diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py
index 113ff99b87a..2a7cb101c4e 100644
--- a/addons/stock_account/models/stock.py
+++ b/addons/stock_account/models/stock.py
@@ -372,6 +372,7 @@ class StockMove(models.Model):
product_tot_qty_available = move.product_id.qty_available + tmpl_dict[move.product_id.id]
rounding = move.product_id.uom_id.rounding
+ qty_done = 0.0
if float_is_zero(product_tot_qty_available, precision_rounding=rounding):
new_std_price = move._get_price_unit()
elif float_is_zero(product_tot_qty_available + move.product_qty, precision_rounding=rounding):
@@ -379,10 +380,11 @@ class StockMove(models.Model):
else:
# Get the standard price
amount_unit = std_price_update.get((move.company_id.id, move.product_id.id)) or move.product_id.standard_price
- qty = forced_qty or move.product_qty
- new_std_price = ((amount_unit * product_tot_qty_available) + (move._get_price_unit() * qty)) / (product_tot_qty_available + move.product_qty)
+ qty_done = move.product_uom._compute_quantity(move.quantity_done, move.product_id.uom_id)
+ qty = forced_qty or qty_done
+ new_std_price = ((amount_unit * product_tot_qty_available) + (move._get_price_unit() * qty)) / (product_tot_qty_available + qty_done)
- tmpl_dict[move.product_id.id] += move.product_qty
+ tmpl_dict[move.product_id.id] += qty_done
# Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products
move.product_id.with_context(force_company=move.company_id.id).sudo().write({'standard_price': new_std_price})
std_price_update[move.company_id.id, move.product_id.id] = new_std_price
diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py
index 50cc57885bb..0450d66e9a1 100644
--- a/addons/stock_account/tests/test_stockvaluation.py
+++ b/addons/stock_account/tests/test_stockvaluation.py
@@ -2489,6 +2489,39 @@ class TestStockValuation(TransactionCase):
move2.move_line_ids.qty_done = 0
self.assertEqual(self.product1.stock_value, -187.5)
+ def test_average_perpetual_4(self):
+ self.product1.product_tmpl_id.cost_method = 'average'
+
+ move1 = self.env['stock.move'].create({
+ 'name': 'Receive 1 unit at 10',
+ 'location_id': self.supplier_location.id,
+ 'location_dest_id': self.stock_location.id,
+ 'product_id': self.product1.id,
+ 'product_uom': self.uom_unit.id,
+ 'product_uom_qty': 1.0,
+ 'price_unit': 10,
+ })
+ move1._action_confirm()
+ move1._action_assign()
+ move1.move_line_ids.qty_done = 1.0
+ move1._action_done()
+
+ move2 = self.env['stock.move'].create({
+ 'name': 'Receive 3 units at 5',
+ 'location_id': self.supplier_location.id,
+ 'location_dest_id': self.stock_location.id,
+ 'product_id': self.product1.id,
+ 'product_uom': self.uom_unit.id,
+ 'product_uom_qty': 3.0,
+ 'price_unit': 5,
+ })
+ move2._action_confirm()
+ move2._action_assign()
+ move2.move_line_ids.qty_done = 1.0
+ move2._action_done()
+
+ self.assertAlmostEqual(self.product1.standard_price, 7.5)
+
def test_average_negative_1(self):
""" Test edit in the past. Receive 10, send 20, edit the second move to only send 10.
"""