Skip to content

Commit 739b1a5

Browse files
committed
[FIX] product_variant_route_mto: add missing inverse
1 parent e80a17c commit 739b1a5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

product_variant_route_mto/models/product_product.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ProductProduct(models.Model):
3030
domain="[('product_selectable', '=', True)]",
3131
store=False,
3232
search="_search_route_ids",
33+
inverse="_inverse_route_ids",
3334
)
3435

3536
def _compute_is_mto(self):
@@ -59,6 +60,19 @@ def _search_route_ids(self, operator, value):
5960
domain += [("product_tmpl_id.route_ids", operator, route_ids)]
6061
return domain
6162

63+
def _inverse_route_ids(self):
64+
mto_routes = self.env["stock.route"].search([("is_mto", "=", True)])
65+
for product in self:
66+
non_mto_routes = product.route_ids - mto_routes
67+
if product.route_ids & mto_routes:
68+
if not product.is_mto:
69+
product.is_mto = True
70+
else:
71+
if product.is_mto:
72+
product.is_mto = False
73+
if product.product_tmpl_id.route_ids != non_mto_routes:
74+
product.product_tmpl_id.route_ids = non_mto_routes
75+
6276
@api.constrains("is_mto")
6377
def _check_template_is_mto(self):
6478
for product in self:

0 commit comments

Comments
 (0)