[FIX] stock: set correct return quantity
Steps to reproduce: -Enable multistep routes for manufacturing -create a MO for 50 products -In internal transfers from Stock to Pre-production validate part of the tansfer (20 units) and create a back order for the remaining qty (30 units) -create and validate another pertail transfer (3 units)with a back order for the remaining quantity (27 units) -create a return for the last validated transfers Bug: the default qty for the return is set to -20 where it should be 3 this commit[1] deducts the previous transfers from the returned amount Fix: only deduct returns from current transfer opw-3104699 [1]:https://github.com/odoo/odoo/commit/7b08f0ae0a39e8f575b21e744de16264b6365704 closes odoo/odoo#115929 X-original-commit: 0278a4a7ba5cdd7a722e5d576d22820a3ee64308 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
d7501075b8
commit
c0d5908c6a
@@ -1232,6 +1232,37 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
|
||||
self.assertEqual(so.order_line[1].qty_delivered, 1)
|
||||
self.assertEqual(so.order_line[1].product_uom.id, uom_km_id)
|
||||
|
||||
def test_multiple_returns(self):
|
||||
# Creates a sale order for 10 products.
|
||||
sale_order = self._get_new_sale_order()
|
||||
# Valids the sale order, then valids the delivery.
|
||||
sale_order.action_confirm()
|
||||
picking = sale_order.picking_ids
|
||||
picking.move_ids.write({'quantity_done': 10})
|
||||
picking.button_validate()
|
||||
|
||||
# Creates a return from the delivery picking.
|
||||
return_picking_form = Form(self.env['stock.return.picking']
|
||||
.with_context(active_ids=picking.ids, active_id=picking.id,
|
||||
active_model='stock.picking'))
|
||||
return_wizard = return_picking_form.save()
|
||||
# Check that the correct quantity is set on the retrun
|
||||
self.assertEqual(return_wizard.product_return_moves.quantity, 10)
|
||||
return_wizard.product_return_moves.quantity = 2
|
||||
# Valids the return picking.
|
||||
res = return_wizard.create_returns()
|
||||
return_picking = self.env['stock.picking'].browse(res['res_id'])
|
||||
return_picking.move_ids.write({'quantity_done': 2})
|
||||
return_picking.button_validate()
|
||||
|
||||
# Creates a second return from the delivery picking.
|
||||
return_picking_form = Form(self.env['stock.return.picking']
|
||||
.with_context(active_ids=picking.ids, active_id=picking.id,
|
||||
active_model='stock.picking'))
|
||||
return_wizard = return_picking_form.save()
|
||||
# Check that the remaining quantity is set on the retrun
|
||||
self.assertEqual(return_wizard.product_return_moves.quantity, 8)
|
||||
|
||||
def test_return_with_mto_and_multisteps(self):
|
||||
"""
|
||||
Suppose a product P and a 3-steps delivery.
|
||||
|
||||
@@ -79,7 +79,7 @@ class ReturnPicking(models.TransientModel):
|
||||
def _prepare_stock_return_picking_line_vals_from_move(self, stock_move):
|
||||
quantity = stock_move.product_qty
|
||||
for move in stock_move.move_dest_ids:
|
||||
if move.origin_returned_move_id and move.origin_returned_move_id != stock_move:
|
||||
if not move.origin_returned_move_id or move.origin_returned_move_id != stock_move:
|
||||
continue
|
||||
if move.state in ('partially_available', 'assigned'):
|
||||
quantity -= sum(move.move_line_ids.mapped('reserved_qty'))
|
||||
|
||||
Reference in New Issue
Block a user