From 935af5f18ed066c6051884e3c4ea56a776e214a4 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 18 Jan 2021 10:40:31 +0100 Subject: [PATCH] Ensure children_ids is computed with proper triggers * Any child_ids changed on a children_ids should recompute locations: otherwise only 2 levels are updated. * Flush any change in the hierarchy before executing the SQL --- stock_location_children/models/stock_location.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stock_location_children/models/stock_location.py b/stock_location_children/models/stock_location.py index f872641f4..efe3d14b1 100644 --- a/stock_location_children/models/stock_location.py +++ b/stock_location_children/models/stock_location.py @@ -17,7 +17,7 @@ class StockLocation(models.Model): help="All the children (multi-level) stock location of this location", ) - @api.depends("child_ids", "child_ids.child_ids") + @api.depends("child_ids", "children_ids.child_ids") def _compute_children_ids(self): query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children FROM stock_location sl2, @@ -30,6 +30,7 @@ class StockLocation(models.Model): AND sub.id IN %s GROUP BY sub.id; """ + self.flush(["location_id", "child_ids"]) self.env.cr.execute(query, (tuple(self.ids),)) rows = self.env.cr.dictfetchall() for loc in self: