FIX: assign value to field compute always

on V13 fields compute must be assign value for avoid cache errors
This commit is contained in:
Carlos Lopez
2020-10-16 07:40:38 -05:00
committed by Kitti U
parent c3fd88e083
commit 51ba3d2d16

View File

@@ -107,20 +107,28 @@ class StockRequest(models.AbstractModel):
@api.depends("product_id", "warehouse_id", "location_id")
def _compute_route_ids(self):
route_obj = self.env["stock.location.route"]
for wh in self.mapped("warehouse_id"):
wh_routes = route_obj.search([("warehouse_ids", "=", wh.id)])
for record in self.filtered(lambda r: r.warehouse_id == wh):
routes = route_obj
if record.product_id:
routes += record.product_id.mapped(
"route_ids"
) | record.product_id.mapped("categ_id").mapped("total_route_ids")
if record.warehouse_id:
routes |= wh_routes
parents = record.get_parents().ids
record.route_ids = routes.filtered(
lambda r: any(p.location_id.id in parents for p in r.rule_ids)
routes = route_obj.search(
[("warehouse_ids", "in", self.mapped("warehouse_id").ids)]
)
routes_by_warehouse = {}
for route in routes:
for warehouse in route.warehouse_ids:
routes_by_warehouse.setdefault(
warehouse.id, self.env["stock.location.route"]
)
routes_by_warehouse[warehouse.id] |= route
for record in self:
routes = route_obj
if record.product_id:
routes += record.product_id.mapped(
"route_ids"
) | record.product_id.mapped("categ_id").mapped("total_route_ids")
if record.warehouse_id and routes_by_warehouse.get(record.warehouse_id.id):
routes |= routes_by_warehouse[record.warehouse_id.id]
parents = record.get_parents().ids
record.route_ids = routes.filtered(
lambda r: any(p.location_id.id in parents for p in r.rule_ids)
)
def get_parents(self):
location = self.location_id