Skip to content

Commit

Permalink
sf checkout: Fix scannig a lot in package and quantity done
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TDu committed Nov 30, 2023
1 parent c71d1f1 commit 4019709
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
29 changes: 15 additions & 14 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
27 changes: 27 additions & 0 deletions shopfloor/tests/test_checkout_scan_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 4019709

Please sign in to comment.