Skip to content

Commit

Permalink
sf checkout: Fix scan lot multiple line with the lot
Browse files Browse the repository at this point in the history
When scanning a lot, if the lot is on multiple lines only one of the
lines should have the quantity updated.
  • Loading branch information
TDu committed Nov 30, 2023
1 parent 4019709 commit 67b7642
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 6 additions & 3 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,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)

Expand Down
32 changes: 32 additions & 0 deletions shopfloor/tests/test_checkout_scan_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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)]
Expand Down

0 comments on commit 67b7642

Please sign in to comment.