[14.0][FIX] stock_move_location: Fix onchange and make editable

This commit is contained in:
RabbitJon-S73
2023-02-14 11:44:33 +01:00
parent e08be889e2
commit b4ac2be568
3 changed files with 36 additions and 19 deletions

View File

@@ -258,3 +258,17 @@ class TestMoveLocation(TestsCommon):
second_line = wizard.stock_move_location_line_ids[1]
second_line.product_id = False
self.assertEqual(second_line._get_available_quantity(), (0, 0))
def test_wizard_different_destinations(self):
"""
Create a picking whose line destinations are differents. The first line is sent
to the origin location.
"""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.onchange_origin_location()
wizard.stock_move_location_line_ids[0].write(
{"destination_location_id": self.internal_loc_1.id}
)
wizard.action_move_location()
locations = self.internal_loc_1 + self.internal_loc_2
self.assertEqual(wizard.picking_id.move_line_ids.location_dest_id, locations)

View File

@@ -155,8 +155,11 @@ class StockMoveLocationWizard(models.TransientModel):
@api.onchange("destination_location_id")
def _onchange_destination_location_id(self):
for line in self.stock_move_location_line_ids:
line.destination_location_id = self.destination_location_id
if self.env.context.get("active_model", False) == "stock.quant":
for line in self.stock_move_location_line_ids:
line.destination_location_id = self.destination_location_id
else:
self.create_lines()
def _clear_lines(self):
self.stock_move_location_line_ids = False
@@ -332,18 +335,22 @@ class StockMoveLocationWizard(models.TransientModel):
not self.env.context.get("origin_location_disable")
and self.origin_location_id
):
lines = []
line_model = self.env["wiz.stock.move.location.line"]
for line_val in self._get_stock_move_location_lines_values():
if line_val.get("max_quantity") <= 0:
continue
line = line_model.create(line_val)
line.max_quantity = line.get_max_quantity()
line.reserved_quantity = line.reserved_quantity
lines.append(line)
self.update(
{"stock_move_location_line_ids": [(6, 0, [line.id for line in lines])]}
)
self.create_lines()
def create_lines(self):
self._clear_lines()
lines = []
line_model = self.env["wiz.stock.move.location.line"]
for line_val in self._get_stock_move_location_lines_values():
if line_val.get("max_quantity") <= 0:
continue
line = line_model.create(line_val)
line.max_quantity = line.get_max_quantity()
line.reserved_quantity = line.reserved_quantity
lines.append(line)
self.update(
{"stock_move_location_line_ids": [(6, 0, [line.id for line in lines])]}
)
def clear_lines(self):
self._clear_lines()

View File

@@ -64,11 +64,7 @@
readonly="1"
force_save="1"
/>
<field
name="destination_location_id"
readonly="1"
force_save="1"
/>
<field name="destination_location_id" />
<field
name="lot_id"
domain="[('product_id', '=', product_id)]"