From 25b16692896e5e09b387428d6ef888f8d8d96732 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Tue, 12 Sep 2023 15:16:22 +0200 Subject: [PATCH] FIX stock_move_common_dest: calling _compute_common_dest_move_ids on new record --- stock_move_common_dest/models/stock_move.py | 5 ++++- .../tests/test_move_common_dest.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/stock_move_common_dest/models/stock_move.py b/stock_move_common_dest/models/stock_move.py index 7cb652daf..330948029 100644 --- a/stock_move_common_dest/models/stock_move.py +++ b/stock_move_common_dest/models/stock_move.py @@ -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),)) diff --git a/stock_move_common_dest/tests/test_move_common_dest.py b/stock_move_common_dest/tests/test_move_common_dest.py index 9af07ff05..8b5520f7e 100644 --- a/stock_move_common_dest/tests/test_move_common_dest.py +++ b/stock_move_common_dest/tests/test_move_common_dest.py @@ -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)