[FIX] stock: extra move in return

- Create a PO with 5 units of A and 10 units of B
- Receive the products
- Return the picking, but return 12 units of A and 10 units of B

The first picking (done state) will contain:
- 7 units of A, 0 qty done => it is an extra move
- 10 units of B, 10 qty done

But another picking (not done) is created, with
- 5 units of A, 12 qty done

The core of the issue is that the `origin_returned_move_id` is not
copied on the extra move. Therefore, it is not merged by `_merge_moves`
since the latter field is in the list of
`_prepare_merge_moves_distinct_fields`.

opw-1882959
This commit is contained in:
Nicolas Martinelli
2018-09-19 08:06:13 +02:00
committed by Nicolas Martinelli
parent 2aa5c81248
commit 7640575a24
2 changed files with 25 additions and 0 deletions
+1
View File
@@ -1031,6 +1031,7 @@ class StockMove(models.Model):
def _prepare_extra_move_vals(self, qty):
vals = {
'origin_returned_move_id': self.origin_returned_move_id.id,
'product_uom_qty': qty,
'picking_id': self.picking_id.id,
'price_unit': self.price_unit,
+24
View File
@@ -252,6 +252,30 @@ class TestPickShip(TestStockCommon):
"Downstream computation from original picking worked"
)
def test_mto_moves_return_extra(self):
picking_pick, picking_client = self.create_pick_ship()
stock_location = self.env['stock.location'].browse(self.stock_location)
self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 10.0)
picking_pick.action_assign()
picking_pick.move_lines[0].move_line_ids[0].qty_done = 10.0
picking_pick.action_done()
self.assertEqual(picking_pick.state, 'done')
self.assertEqual(picking_client.state, 'assigned')
# return more than we've done
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0])\
.create({})
stock_return_picking.product_return_moves.quantity = 12.0 # Return 2 extra
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
# Verify the extra move has been merged with the original move
self.assertAlmostEqual(return_pick.move_lines.product_uom_qty, 12.0)
self.assertAlmostEqual(return_pick.move_lines.quantity_done, 0.0)
self.assertAlmostEqual(return_pick.move_lines.reserved_availability, 10.0)
def test_mto_resupply_cancel_ship(self):
""" This test simulates a pick pack ship with a resupply route
set. Pick and pack are validated, ship is cancelled. This test