diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 5b83158a843..ab76630efad 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1313,3 +1313,40 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): line.product_uom_qty = 8 self.assertEqual(so.picking_ids.move_ids.product_uom_qty, 8) + + def test_backorder_and_decrease_sol_qty(self): + """ + 2 steps delivery + SO with 10 x P + Process pickings of 6 x P with backorders + Update SO: 7 x P + Backorder should be updated: 1 x P + """ + warehouse = self.company_data['default_warehouse'] + warehouse.delivery_steps = 'pick_ship' + stock_location = warehouse.lot_stock_id + out_location = warehouse.wh_output_stock_loc_id + customer_location = self.env.ref('stock.stock_location_customers') + + so = self._get_new_sale_order() + so.action_confirm() + pick01, ship01 = so.picking_ids + + pick01.move_line_ids.qty_done = 6 + pick01._action_done() + pick02 = pick01.backorder_ids + + ship01.move_line_ids[0].qty_done = 6 + ship01._action_done() + ship02 = ship01.backorder_ids + + so.order_line.product_uom_qty = 7 + + self.assertRecordValues(so.picking_ids.move_ids.sorted('id'), [ + {'location_id': out_location.id, 'location_dest_id': customer_location.id, 'product_uom_qty': 6.0, 'quantity_done': 6.0, 'state': 'done'}, + {'location_id': stock_location.id, 'location_dest_id': out_location.id, 'product_uom_qty': 6.0, 'quantity_done': 6.0, 'state': 'done'}, + {'location_id': stock_location.id, 'location_dest_id': out_location.id, 'product_uom_qty': 1.0, 'quantity_done': 0.0, 'state': 'assigned'}, + {'location_id': out_location.id, 'location_dest_id': customer_location.id, 'product_uom_qty': 1.0, 'quantity_done': 0.0, 'state': 'waiting'}, + ]) + self.assertEqual(ship01.move_ids.move_orig_ids, (pick01 | pick02).move_ids) + self.assertEqual(ship02.move_ids.move_orig_ids, (pick01 | pick02).move_ids) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 934233297b8..6b8563f8e14 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1842,7 +1842,7 @@ Please change the quantity done or the rounding precision of your unit of measur def _prepare_move_split_vals(self, qty): vals = { 'product_uom_qty': qty, - 'procure_method': 'make_to_stock', + 'procure_method': self.procure_method, 'move_dest_ids': [(4, x.id) for x in self.move_dest_ids if x.state not in ('done', 'cancel')], 'move_orig_ids': [(4, x.id) for x in self.move_orig_ids], 'origin_returned_move_id': self.origin_returned_move_id.id,