mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
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:
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user