[FIX] stock_account: dropship & AVCO

- Activate: 'Order-Specific Routes' and 'Dropshipping'
- Create a stockable product in AVCO + AUTO
- Purchase the product at $10 and validate the receipt
  => One product @ $10 in stock
- Sell the product via dropshipping
- A PO is generated, change unit price to $20, validate
- Validate the picking

The product in stock has now a cost of $15, i.e. the dropship impacted
the cost of the product.

Now if the product in stock is sold, the product will go out at a cost
of $15. This will lead to a wrong accounting valuation (0 product in
stock with -$5 in stock).

opw-1922289
opw-1935272
opw-1937672

closes odoo/odoo#31786

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-03-13 09:55:40 +00:00
parent 170c7632f2
commit 1c912767d1
2 changed files with 52 additions and 1 deletions
+1 -1
View File
@@ -377,7 +377,7 @@ class StockMove(models.Model):
tmpl_dict = defaultdict(lambda: 0.0)
# adapt standard price on incomming moves if the product cost_method is 'average'
std_price_update = {}
for move in self.filtered(lambda move: move.location_id.usage in ('supplier', 'production') and move.product_id.cost_method == 'average'):
for move in self.filtered(lambda move: move._is_in() and move.product_id.cost_method == 'average'):
product_tot_qty_available = move.product_id.qty_available + tmpl_dict[move.product_id.id]
rounding = move.product_id.uom_id.rounding
@@ -2628,6 +2628,57 @@ class TestStockValuation(TransactionCase):
self.assertAlmostEqual(self.product1.standard_price, 14.0)
def test_average_perpetual_8(self):
""" Receive 1@10, then dropship 1@20, finally return the dropship. Dropship should not
impact the price.
"""
self.product1.product_tmpl_id.cost_method = 'average'
move1 = self.env['stock.move'].create({
'name': 'IN 1@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,
'price_unit': 10,
})
move1._action_confirm()
move1.quantity_done = 1
move1._action_done()
self.assertAlmostEqual(self.product1.standard_price, 10)
move2 = self.env['stock.move'].create({
'name': 'IN 1@20',
'location_id': self.supplier_location.id,
'location_dest_id': self.customer_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 1,
'price_unit': 20,
})
move2._action_confirm()
move2.quantity_done = 1
move2._action_done()
self.assertAlmostEqual(self.product1.standard_price, 10.0)
move3 = self.env['stock.move'].create({
'name': 'IN 1@20',
'location_id': self.customer_location.id,
'location_dest_id': self.supplier_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 1,
'price_unit': 20,
})
move3._action_confirm()
move3.quantity_done = 1
move3._action_done()
self.assertAlmostEqual(self.product1.standard_price, 10.0)
def test_average_negative_1(self):
""" Test edit in the past. Receive 10, send 20, edit the second move to only send 10.
"""