[IMP] stock_move_location: improve planned transfer

This commit ensures stock move lines with the selected lot_id are in the 'assigned' state when a specific product with a lot_id is chosen in the stock move location for a planned transfer. It resolves the issue where the selected lot_id for a specific product was being discarded and a different lot_id was inadvertently assigned in the move line.
This commit is contained in:
Aungkokolin1997
2023-12-01 08:07:36 +06:30
committed by Yoshi Tashiro
parent 8db317e1bc
commit 8a3a856d74
2 changed files with 41 additions and 6 deletions

View File

@@ -124,7 +124,28 @@ class TestMoveLocation(TestsCommon):
wizard.action_move_location()
picking = wizard.picking_id
self.assertEqual(picking.state, "assigned")
self.assertEqual(len(picking.move_line_ids), 7)
self.assertEqual(
len(wizard.stock_move_location_line_ids), len(picking.move_line_ids)
)
wizard_lines = sorted(
[
(line.product_id.id, line.lot_id.id, line.move_quantity)
for line in wizard.stock_move_location_line_ids
],
key=lambda x: (x[0], x[1]),
)
picking_lines = sorted(
[
(line.product_id.id, line.lot_id.id, line.reserved_uom_qty)
for line in picking.move_line_ids
],
key=lambda x: (x[0], x[1]),
)
self.assertEqual(
wizard_lines,
picking_lines,
"Mismatch between move location lines and move lines",
)
self.assertEqual(
sorted(picking.move_line_ids.mapped("reserved_uom_qty")),
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 123.0],

View File

@@ -207,9 +207,26 @@ class StockMoveLocationWizard(models.TransientModel):
def _create_move(self, picking, lines):
self.ensure_one()
move = self.env["stock.move"].create(self._get_move_values(picking, lines))
if not self.env.context.get("planned"):
lines.create_move_lines(picking, move)
if self.env.context.get("planned"):
for line in lines:
line.create_move_lines(picking, move)
available_quantity = self.env["stock.quant"]._get_available_quantity(
line.product_id,
line.origin_location_id,
lot_id=line.lot_id,
strict=False,
)
move._update_reserved_quantity(
line.move_quantity,
available_quantity,
line.origin_location_id,
lot_id=line.lot_id,
strict=False,
)
# Force the state to be assigned, instead of _action_assign,
# to avoid discarding the selected move_location_line.
move.state = "assigned"
move.move_line_ids.write({"state": "assigned"})
return move
def _unreserve_moves(self):
@@ -255,9 +272,6 @@ class StockMoveLocationWizard(models.TransientModel):
moves_to_reassign = self._unreserve_moves()
picking.button_validate()
moves_to_reassign._action_assign()
else:
picking.action_confirm()
picking.action_assign()
self.picking_id = picking
return self._get_picking_action(picking.id)