Skip to content

Commit

Permalink
sf checkout: Fix scannig a lot 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, all the lines with the same
product related to that lot. 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 c114af4 commit c71d1f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
16 changes: 8 additions & 8 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,18 +581,18 @@ def _select_lines_from_lot(
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
)

first_allowed_line = fields.first(lines)
return self._select_lines_from_product(
picking,
selection_lines,
first_allowed_line.product_id,
prefill_qty=prefill_qty,
check_lot=False,
# 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
)
lines = self._select_lines(
lines, prefill_qty=prefill_qty, related_lines=related_lines
)
return self._response_for_select_package(picking, lines)

def _select_lines_from_serial(self, picking, selection_lines, lot, **kw):
# Search for serial number is actually the same as searching for lot (as of v14...)
Expand Down
25 changes: 25 additions & 0 deletions shopfloor/tests/test_checkout_scan_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_scan_line_product_packaging_ok(self):
)

def test_scan_line_product_lot_ok(self):
"""Check scanning a lot and there is only one lot for that product."""
picking = self._create_picking(
lines=[(self.product_a, 1), (self.product_a, 1), (self.product_b, 1)]
)
Expand All @@ -121,6 +122,30 @@ def test_scan_line_product_lot_ok(self):
related_lines = picking.move_line_ids - first_line
self._test_scan_line_ok(lot.name, first_line, related_lines)

def test_scan_line_product_lot_ok_multiple_lot(self):
"""Check scanning a lot and there is two different lot for that product."""
picking = self._create_picking(
lines=[(self.product_a, 1), (self.product_a, 1), (self.product_b, 1)]
)
# 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, None, 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, None, lot_2
)
self._fill_stock_for_moves(picking.move_lines[1], 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 c71d1f1

Please sign in to comment.