diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index e6bd2700823..2857f3caf6f 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -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. diff --git a/addons/stock/wizard/stock_picking_return.py b/addons/stock/wizard/stock_picking_return.py index 80db63fcc54..08e993b296b 100644 --- a/addons/stock/wizard/stock_picking_return.py +++ b/addons/stock/wizard/stock_picking_return.py @@ -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'))