FIX stock_move_common_dest: calling _compute_common_dest_move_ids on new record

This commit is contained in:
Pierre Verkest
2023-09-12 15:16:22 +02:00
parent a16b9dd945
commit 25b1669289
2 changed files with 16 additions and 1 deletions

View File

@@ -5,7 +5,6 @@ from odoo.osv.expression import FALSE_DOMAIN
class StockMove(models.Model):
_inherit = "stock.move"
common_dest_move_ids = fields.Many2many(
@@ -45,6 +44,10 @@ class StockMove(models.Model):
"move_dest_ids.picking_id.move_lines.move_orig_ids",
)
def _compute_common_dest_move_ids(self):
if not self.ids:
for move in self:
move.common_dest_move_ids = [(5, 0, 0)]
return
self._flush_common_dest_move_query()
sql = self._common_dest_move_query()
self.env.cr.execute(sql, (tuple(self.ids),))

View File

@@ -172,3 +172,15 @@ class TestCommonMoveDest(SavepointCase):
),
pick_move_1a | pick_move_1b,
)
def test_compute_common_dest_move_ids_on_new_record(self):
"""Discovered while testing MRP with code such as::
with Form(cls.env["mrp.production"]) as mo_form:
mo_form.product_id = cls.product
This call _compute_common_dest_move_ids on a new instance
(without stock_move db record)
"""
move = self.env["stock.move"].new({})
self.assertFalse(move.common_dest_move_ids)