[FIX] stock_move_location: fix planned transfer incorrect reserved_uom_qty

This PR fixes stock quant matching in _get_gather_domain by setting strict=True,
ensuring precise matching based on lot, package, and location. This change addresses
issues arising from the previous approach, which could lead to the inclusion of
unnecessary quants, such as those without an owner or lot.
This commit is contained in:
Aungkokolin1997
2024-04-09 09:39:21 +00:00
parent 6a79163834
commit 7ddb56a36c
2 changed files with 73 additions and 2 deletions

View File

@@ -151,6 +151,77 @@ class TestMoveLocation(TestsCommon):
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 123.0],
)
def test_planned_transfer_strict(self):
product = self.env["product.product"].create(
{"name": "Test", "type": "product", "tracking": "lot"}
)
lot = self.env["stock.lot"].create(
{
"name": "Test lot",
"product_id": product.id,
}
)
self.set_product_amount(
product,
self.internal_loc_1,
10.0,
)
self.set_product_amount(
product,
self.internal_loc_1,
10.0,
lot_id=lot,
)
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.onchange_origin_location()
wizard = wizard.with_context(planned=True)
location_lines = wizard.stock_move_location_line_ids.filtered(
lambda r: r.product_id.id != product.id or r.lot_id.id != lot.id
)
location_lines.unlink()
wizard.action_move_location()
picking = wizard.picking_id
self.assertEqual(picking.state, "assigned")
self.assertEqual(
len(wizard.stock_move_location_line_ids), len(picking.move_line_ids)
)
location_line = wizard.stock_move_location_line_ids
wizard_lines = [
location_line.product_id.id,
location_line.lot_id.id,
location_line.move_quantity,
]
line = picking.move_line_ids
picking_lines = [line.product_id.id, line.lot_id.id, line.reserved_uom_qty]
self.assertEqual(
wizard_lines,
picking_lines,
"Mismatch between move location lines and move lines",
)
self.assertEqual(
picking.move_line_ids.reserved_uom_qty,
10.0,
)
# Create planned transfer for same quant
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.onchange_origin_location()
wizard = wizard.with_context(planned=True)
location_lines = wizard.stock_move_location_line_ids.filtered(
lambda r: r.product_id.id != product.id or r.lot_id.id != lot.id
)
location_lines.unlink()
wizard.action_move_location()
picking = wizard.picking_id
self.assertEqual(picking.state, "assigned")
self.assertEqual(
len(wizard.stock_move_location_line_ids), len(picking.move_line_ids)
)
self.assertEqual(
picking.move_line_ids.mapped("reserved_uom_qty"),
[0.0],
)
def test_quant_transfer(self):
"""Test quants transfer."""
quants = self.product_lots.stock_quant_ids

View File

@@ -218,7 +218,7 @@ class StockMoveLocationWizard(models.TransientModel):
lot_id=line.lot_id,
package_id=line.package_id,
owner_id=line.owner_id,
strict=False,
strict=True,
)
move._update_reserved_quantity(
line.move_quantity,
@@ -227,7 +227,7 @@ class StockMoveLocationWizard(models.TransientModel):
lot_id=line.lot_id,
package_id=line.package_id,
owner_id=line.owner_id,
strict=False,
strict=True,
)
# Force the state to be assigned, instead of _action_assign,
# to avoid discarding the selected move_location_line.