diff --git a/product_route_profile/__manifest__.py b/product_route_profile/__manifest__.py
index 7519aed60..e3da6ad1b 100644
--- a/product_route_profile/__manifest__.py
+++ b/product_route_profile/__manifest__.py
@@ -5,7 +5,7 @@
{
"name": "Product Route Profile",
"summary": "Add Route profile concept on product",
- "version": "15.0.1.0.0",
+ "version": "17.0.1.0.0",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Akretion, Odoo Community Association (OCA)",
diff --git a/product_route_profile/hooks.py b/product_route_profile/hooks.py
index c0ba61394..77f5a20fa 100644
--- a/product_route_profile/hooks.py
+++ b/product_route_profile/hooks.py
@@ -4,18 +4,14 @@
from collections import defaultdict
-from odoo import SUPERUSER_ID, api
-
-def post_init_hook(cr, registry):
+def post_init_hook(env):
def get_profile(route_ids):
route_ids = tuple(set(route_ids))
profile = route2profile.get(route_ids)
if not profile:
profile_name = ""
- route_names = [
- rec.name for rec in env["stock.location.route"].browse(route_ids)
- ]
+ route_names = [rec.name for rec in env["stock.route"].browse(route_ids)]
profile_name = " / ".join(route_names)
profile = env["route.profile"].create(
{
@@ -26,13 +22,12 @@ def post_init_hook(cr, registry):
route2profile[route_ids] = profile
return profile
- env = api.Environment(cr, SUPERUSER_ID, {})
query = """
SELECT product_id, array_agg(route_id)
FROM stock_route_product group by product_id;
"""
- cr.execute(query)
- results = cr.fetchall()
+ env.cr.execute(query)
+ results = env.cr.fetchall()
route2profile = {}
profile2product = defaultdict(lambda: env["product.template"])
for row in results:
diff --git a/product_route_profile/models/product_template.py b/product_route_profile/models/product_template.py
index a6b158975..d4923d1c4 100644
--- a/product_route_profile/models/product_template.py
+++ b/product_route_profile/models/product_template.py
@@ -64,11 +64,24 @@ class ProductTemplate(models.Model):
"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)
+ @api.model_create_multi
+ def create(self, vals_list):
+ vals_with_profile = []
+ vals_without_profile = []
+ for vals in vals_list:
+ route_profile_id = vals.get("route_profile_id")
+ if route_profile_id:
+ vals = vals.copy()
+ route_profile = self.env["route.profile"].browse(route_profile_id)
+ vals["route_ids"] = [(6, 0, route_profile.route_ids.ids)]
+ vals_with_profile.append(vals)
+ else:
+ vals_without_profile.append(vals)
+ res = self.env["product.template"]
+ if vals_without_profile:
+ res += super().create(vals_without_profile)
+ if vals_with_profile:
+ res += super(
+ ProductTemplate, self.with_context(skip_inverse_route_ids=True)
+ ).create(vals_with_profile)
+ return res
diff --git a/product_route_profile/models/route_profile.py b/product_route_profile/models/route_profile.py
index 12df849b4..e71b52067 100644
--- a/product_route_profile/models/route_profile.py
+++ b/product_route_profile/models/route_profile.py
@@ -14,10 +14,9 @@ class RouteProfile(models.Model):
comodel_name="res.company",
default=lambda self: self.env.company.id,
required=False,
- string="Company",
)
route_ids = fields.Many2many(
- "stock.location.route",
+ comodel_name="stock.route",
string="Routes",
domain=[("product_selectable", "=", True)],
)
diff --git a/product_route_profile/tests/test_product_route_profile.py b/product_route_profile/tests/test_product_route_profile.py
index 2ff6636e4..9e41e07a8 100644
--- a/product_route_profile/tests/test_product_route_profile.py
+++ b/product_route_profile/tests/test_product_route_profile.py
@@ -8,7 +8,7 @@ from odoo.tests.common import TransactionCase
class TestProductRouteProfile(TransactionCase):
@classmethod
def setUpClass(cls):
- super(TestProductRouteProfile, cls).setUpClass()
+ super().setUpClass()
cls.company_bis = cls.env["res.company"].create(
{
diff --git a/product_route_profile/views/product_template.xml b/product_route_profile/views/product_template.xml
index 33c49e431..93f073c3c 100644
--- a/product_route_profile/views/product_template.xml
+++ b/product_route_profile/views/product_template.xml
@@ -9,16 +9,16 @@
- {'invisible': True}
+ True