Merge PR #1843 into 14.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2023-11-03 17:22:51 +00:00
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)