diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c6aa9d39308..be50495305d 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1009,17 +1009,12 @@ class StockMove(models.Model): move._action_cancel() # Create extra moves where necessary - for move in moves.filtered(lambda m: m.state != 'cancel'): - # Here, the `quantity_done` was already rounded to the product UOM by the `do_produce` wizard. However, - # it is possible that the user changed the value before posting the inventory by a value that should be - # rounded according to the move's UOM. In this specific case, we chose to round up the value, because it - # is what is expected by the user (if i consumed/produced a little more, the whole UOM unit should be - # consumed/produced and the moves are split correctly). - # FIXME: move rounding to move line - # rounding = move.product_uom.rounding - # move.quantity_done = float_round(move.quantity_done, precision_rounding=rounding, rounding_method ='UP') + for move in moves: + if move.state == 'cancel' or move.quantity_done <= 0: + continue moves_todo |= move moves_todo |= move._create_extra_move() + # Split moves where necessary and move quants for move in moves_todo: rounding = move.product_uom.rounding diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index a3a6b0ae46b..45e898856b7 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -743,6 +743,51 @@ class TestSinglePicking(TestStockCommon): backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)]) self.assertEqual(backorder.state, 'confirmed') + def test_backorder_3(self): + """ Check the good behavior of creating a backorder for an available move on a picking with + two available moves. + """ + 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, + }) + + # make some stock + 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.productA, pack_location, 2) + + # assign to partially available + delivery_order.action_confirm() + delivery_order.action_assign() + self.assertEqual(delivery_order.state, 'assigned') + + delivery_order.move_lines[0].move_line_ids[0].qty_done = 2 + delivery_order.do_transfer() + + backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)]) + self.assertEqual(backorder.state, 'confirmed') + 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