[FIX] product_route_profile _inverse_route_ids store selected route_profile_id

This commit is contained in:
Agustin Wisky
2023-04-12 19:31:23 -03:00
parent 5e1a5dd910
commit d273a3bfaa
2 changed files with 22 additions and 0 deletions

View File

@@ -46,6 +46,8 @@ class ProductTemplate(models.Model):
]
def _inverse_route_ids(self):
if self._context.get("skip_inverse_route_ids"):
return
profiles = self.env["route.profile"].search([])
for rec in self:
for profile in profiles:
@@ -61,3 +63,12 @@ class ProductTemplate(models.Model):
"name": " / ".join(self.route_ids.mapped("name")),
"route_ids": [(6, 0, self.route_ids.ids)],
}
@api.model
def create(self, vals):
route_profile_id = vals.get("route_profile_id", False)
if route_profile_id:
route_profile = self.env["route.profile"].browse(route_profile_id)
vals["route_ids"] = [(6, 0, route_profile.route_ids.ids)]
self = self.with_context(skip_inverse_route_ids=True)
return super(ProductTemplate, self).create(vals)

View File

@@ -70,3 +70,14 @@ class TestProductRouteProfile(SavepointCase):
self.product.with_company(self.env.company).route_ids,
self.route_profile_1.route_ids,
)
def test_3_product_creation_with_route_profile(self):
product = self.env["product.template"].create(
{
"name": "Template 2",
"company_id": False,
"route_profile_id": self.route_profile_1.id,
}
)
self.assertEqual(product.route_profile_id.id, self.route_profile_1.id)