From 4019709ff00bdc165bc794ec3e3d9b597d8692ce Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Thu, 30 Nov 2023 10:35:14 +0100 Subject: [PATCH] sf checkout: Fix scannig a lot in package and quantity done With the no-prefill-qty option not set. When selecting a line by scanning a lot, that is in a package. All the lines in the package have their quantity done set! But only the line with the lot scanned should have the quantity done updated. --- shopfloor/services/checkout.py | 29 +++++++++++----------- shopfloor/tests/test_checkout_scan_line.py | 27 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/shopfloor/services/checkout.py b/shopfloor/services/checkout.py index ce427673a4..95864f6406 100644 --- a/shopfloor/services/checkout.py +++ b/shopfloor/services/checkout.py @@ -564,31 +564,32 @@ def _select_lines_from_lot( "body": _("Lot is not in the current transfer."), }, ) - - # When lots are as units outside of packages, we can select them for - # packing, but if they are in a package, we want the user to scan the packages. - # If the product is only in one package though, scanning the lot selects - # the package. + # Related lines will be visible with the line picked (qty done changed) + related_lines = self.env["stock.move.line"] packages = lines.mapped("package_id") # Do not use mapped here: we want to see if we have more than one # package, but also if we have one lot as a package and the same lot as # a unit in another line. In both cases, we want the user to scan the # package. if packages and len({line.package_id for line in lines}) > 1: + # The lot is spread out in multiple packages, ask to scan a package return self._response_for_select_line( picking, message=self.msg_store.lot_multiple_packages_scan_package() ) elif packages: - # Select all the lines of the package when we scan a lot in a - # package and we have only one. - - return self._select_lines_from_package( - picking, selection_lines, packages, prefill_qty=prefill_qty, **kw + # The lot is only in one package + # Related lines are the one in the same package + related_lines = selection_lines.filtered( + lambda l: l.package_id == packages and l.lot_id != lot ) - # Not in a package. related lines are all other lines not in a package - related_lines = selection_lines.filtered( - lambda l: not l.package_id and l.lot_id != lot - ) + else: + # Lot as units outside of packages, can be selected for packing. + # Related lines are all other lines not in a package + 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 lines = self._select_lines( lines, prefill_qty=prefill_qty, related_lines=related_lines ) diff --git a/shopfloor/tests/test_checkout_scan_line.py b/shopfloor/tests/test_checkout_scan_line.py index ad3ee38d9d..54a36cdaea 100644 --- a/shopfloor/tests/test_checkout_scan_line.py +++ b/shopfloor/tests/test_checkout_scan_line.py @@ -146,6 +146,33 @@ def test_scan_line_product_lot_ok_multiple_lot(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_in_package_ok(self): + """Check scanning a lot in a package with other products.""" + picking = self._create_picking( + lines=[(self.product_a, 1), (self.product_a, 1), (self.product_b, 1)] + ) + package = self.env["stock.quant.package"].create({"name": "packTST001"}) + # For product A, lets have two lines with different lot + 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, package, lot_1 + ) + lot_2 = 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, package, lot_2 + ) + self._fill_stock_for_moves( + picking.move_lines[1], in_package=package, in_lot=True + ) + picking.action_assign() + line_with_lot_1 = picking.move_line_ids.filtered(lambda l: l.lot_id == lot_1) + 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)]