mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[FIX] product_route_profile _inverse_route_ids store selected route_profile_id
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user