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
This commit is contained in:
Guewen Baconnier
2021-01-18 10:40:31 +01:00
committed by hparfr
parent ef2f062cbb
commit 247da988cd

View File

@@ -17,7 +17,7 @@ class StockLocation(models.Model):
help="All the children (multi-level) stock location of this location", 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): def _compute_children_ids(self):
query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children
FROM stock_location sl2, FROM stock_location sl2,
@@ -30,6 +30,7 @@ class StockLocation(models.Model):
AND sub.id IN %s AND sub.id IN %s
GROUP BY sub.id; GROUP BY sub.id;
""" """
self.flush(["location_id", "child_ids"])
self.env.cr.execute(query, (tuple(self.ids),)) self.env.cr.execute(query, (tuple(self.ids),))
rows = self.env.cr.dictfetchall() rows = self.env.cr.dictfetchall()
for loc in self: for loc in self: