Skip to content

Commit

Permalink
[FIX] stock_account: Average Cost
Browse files Browse the repository at this point in the history
- Create a product where the associated product category has Costing
  Method "Average Cost (AVCO)"
- Create a PO. Order:
  2 units at 40
  4 units at 35
- Receive the picking

The cost of the product is set at 35 (or 40, depending on the order of
the lines in the PO).

Since we are in a situation where the available quantity is zero, we
enter in the `if float_is_zero...` condition, where the `qty_done` is
not set.

We should set it in all cases.

opw-1907328
  • Loading branch information
nim-odoo committed Jan 22, 2019
1 parent 102467a commit 8017033
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 1 addition & 2 deletions addons/stock_account/models/stock.py
Expand Up @@ -381,7 +381,7 @@ def product_price_update_before_done(self, forced_qty=None):
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
qty_done = move.product_uom._compute_quantity(move.quantity_done, move.product_id.uom_id)
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) or \
Expand All @@ -390,7 +390,6 @@ def product_price_update_before_done(self, forced_qty=None):
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_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)

Expand Down
34 changes: 34 additions & 0 deletions addons/stock_account/tests/test_stockvaluation.py
Expand Up @@ -2554,6 +2554,40 @@ def test_average_perpetual_5(self):
self.assertAlmostEqual(self.product1.qty_at_date, 0.0)
self.assertAlmostEqual(self.product1.stock_value, 0.0)

def test_average_perpetual_6(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

move2 = self.env['stock.move'].create({
'name': 'Receive 1 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': 1.0,
'price_unit': 5,
})
move2._action_confirm()
move2._action_assign()
move2.move_line_ids.qty_done = 1.0

# Receive both at the same time
(move1 | 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.
"""
Expand Down

0 comments on commit 8017033

Please sign in to comment.