diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index fe54a445608..a9ef6fc724d 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -2033,7 +2033,9 @@ Please change the quantity done or the rounding precision of your unit of measur if move.state not in ('partially_available', 'assigned'): continue for move_line in move.move_line_ids: - if move.has_tracking != 'none' and not (move_line.lot_id or move_line.lot_name): + if move.has_tracking != 'none' and ( + (move.picking_type_id.use_existing_lots and not move_line.lot_id) or + (move.picking_type_id.use_create_lots and not move_line.lot_name)): continue move_line.qty_done = move_line.reserved_uom_qty diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 70cb09a04cb..4f277e44262 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -4575,6 +4575,32 @@ class StockMove(TransactionCase): self.assertEqual(receipt2.state, 'done') self.assertEqual(receipt3.state, 'done') + def test_immediate_validate_9_tracked_move_with_0_qty_done(self): + """When trying to validate a picking as an immediate transfer, the done + quantity of tracked move should be automatically fulfilled if the + picking type doesn't use new or existing LN/SN.""" + picking_type_receipt = self.env.ref('stock.picking_type_in') + picking_type_receipt.use_create_lots = False + picking_type_receipt.use_existing_lots = False + + picking_form = Form(self.env['stock.picking']) + picking_form.picking_type_id = picking_type_receipt + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.product_serial + move.product_uom_qty = 4 + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.product_lot + move.product_uom_qty = 20 + receipt = picking_form.save() + receipt.action_confirm() + + immediate_wizard = receipt.button_validate() + immediate_wizard_form = Form( + self.env[immediate_wizard['res_model']].with_context(immediate_wizard['context']) + ).save() + immediate_wizard_form.process() + self.assertEqual(receipt.state, 'done') + def test_set_quantity_done_1(self): move1 = self.env['stock.move'].create({ 'name': 'test_set_quantity_done_1',