diff --git a/shopfloor/services/checkout.py b/shopfloor/services/checkout.py index 8d84b7c11b..cc7ee1a241 100644 --- a/shopfloor/services/checkout.py +++ b/shopfloor/services/checkout.py @@ -650,10 +650,13 @@ def _select_lines_from_lot( related_lines = selection_lines.filtered( lambda l: not l.package_id and l.lot_id != lot ) - # FIXME if multiple lines - only one should have its qty-done changed. - # this is realted to the option no-prefill-qty not enabled + # Only one line selected should have its quantity done updated + line_to_update = fields.first(lines) + if len(lines) > 1: + related_lines |= lines - line_to_update + lines = self._select_lines( - lines, prefill_qty=prefill_qty, related_lines=related_lines + line_to_update, prefill_qty=prefill_qty, related_lines=related_lines ) return self._response_for_select_package(picking, lines, message=message) diff --git a/shopfloor/tests/test_checkout_scan_line.py b/shopfloor/tests/test_checkout_scan_line.py index b27a959f4e..ab41afab74 100644 --- a/shopfloor/tests/test_checkout_scan_line.py +++ b/shopfloor/tests/test_checkout_scan_line.py @@ -175,6 +175,38 @@ def test_scan_line_product_lot_in_package_ok(self): related_lines = picking.move_line_ids - line_with_lot_1 self._test_scan_line_ok(lot_1.name, line_with_lot_1, related_lines) + def test_scan_line_product_lot_on_multiple_line_ok(self): + """Check scanning a lot set on multiple lines of the transfer.""" + picking = self._create_picking( + lines=[(self.product_a, 1), (self.product_a, 1), (self.product_b, 1)] + ) + sub_location = ( + self.env["stock.location"] + .sudo() + .create( + { + "location_id": picking.location_id.id, + "name": "sub location to have lot on multiple lines", + } + ) + ) + # For product A, lets have two lines with the same lot + # For that update the stock on two different location + lot_1 = self.env["stock.production.lot"].create( + {"product_id": self.product_a.id, "company_id": self.env.company.id} + ) + self._update_qty_in_location( + picking.location_id, self.product_a, 1, None, lot_1 + ) + self._update_qty_in_location(sub_location, self.product_a, 1, None, lot_1) + self._fill_stock_for_moves(picking.move_lines[1], in_package=False, in_lot=True) + picking.action_assign() + self.assertTrue(len(picking.move_line_ids), 3) + # Only the first line with the lot should be updated + line_with_lot_1 = picking.move_line_ids.filtered(lambda l: l.lot_id == lot_1)[0] + related_lines = picking.move_line_ids - line_with_lot_1 + self._test_scan_line_ok(lot_1.name, line_with_lot_1, related_lines) + def test_scan_line_product_in_one_package_all_package_lines_ok(self): picking = self._create_picking( lines=[(self.product_a, 10), (self.product_b, 10)]