From 0bf5e1ac684457b8cf1edd8bc4a4e33bad0cecde Mon Sep 17 00:00:00 2001 From: Arnaud Baes Date: Wed, 23 Jan 2019 12:37:56 +0000 Subject: [PATCH] [FIX] stock: Backorders A move with the 0 as product_uom_qty must be cancelled when 'no_backorder' is selected TaskID: 1932050 closes odoo/odoo#30474 --- addons/stock/models/stock_move.py | 2 +- addons/stock/tests/test_move2.py | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 83e979d8de4..4881c84d591 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1090,7 +1090,7 @@ class StockMove(models.Model): # this operation could trigger a merge of moves. for move in moves: if move.quantity_done <= 0: - if float_compare(move.product_uom_qty, 0.0, precision_rounding=move.product_uom.rounding) == 0: + if float_compare(move.product_uom_qty, 0.0, precision_rounding=move.product_uom.rounding) == 0 or cancel_backorder: move._action_cancel() # Create extra moves where necessary diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 71df404527e..13b092a9407 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -830,6 +830,55 @@ class TestSinglePicking(TestStockCommon): backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)]) self.assertEqual(backorder.state, 'confirmed') + def test_backorder_4(self): + """ Check the good behavior if no backorder are created + for a picking with a missing product. + """ + delivery_order = self.env['stock.picking'].create({ + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + 'partner_id': self.partner_delta_id, + 'picking_type_id': self.picking_type_out, + }) + self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 2, + 'product_uom': self.productA.uom_id.id, + 'picking_id': delivery_order.id, + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + }) + self.MoveObj.create({ + 'name': self.productA.name, + 'product_id': self.productB.id, + 'product_uom_qty': 2, + 'product_uom': self.productB.uom_id.id, + 'picking_id': delivery_order.id, + 'location_id': self.pack_location, + 'location_dest_id': self.customer_location, + }) + + # Update available quantities for each products + pack_location = self.env['stock.location'].browse(self.pack_location) + self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 2) + self.env['stock.quant']._update_available_quantity(self.productB, pack_location, 2) + + delivery_order.action_confirm() + delivery_order.action_assign() + self.assertEqual(delivery_order.state, 'assigned') + + # Process only one product without creating a backorder + delivery_order.move_lines[0].move_line_ids[0].qty_done = 2 + backorder_wizard = self.env['stock.backorder.confirmation'].create({'pick_ids': [(4, delivery_order.id)]}) + backorder_wizard.process_cancel_backorder() + + # No backorder should be created and the move corresponding to the missing product should be cancelled + backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)]) + self.assertFalse(backorder) + self.assertEquals(delivery_order.state, 'done') + self.assertEquals(delivery_order.move_lines[1].state, 'cancel') + def test_extra_move_1(self): """ Check the good behavior of creating an extra move in a delivery order. This usecase simulates the delivery of 2 item while the initial stock move had to move 1 and there's