mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] product_route_profile: Migration to 17.0
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Product Route Profile",
|
"name": "Product Route Profile",
|
||||||
"summary": "Add Route profile concept on product",
|
"summary": "Add Route profile concept on product",
|
||||||
"version": "15.0.1.0.0",
|
"version": "17.0.1.0.0",
|
||||||
"category": "Warehouse",
|
"category": "Warehouse",
|
||||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||||
"author": "Akretion, Odoo Community Association (OCA)",
|
"author": "Akretion, Odoo Community Association (OCA)",
|
||||||
|
|||||||
@@ -4,18 +4,14 @@
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from odoo import SUPERUSER_ID, api
|
|
||||||
|
|
||||||
|
def post_init_hook(env):
|
||||||
def post_init_hook(cr, registry):
|
|
||||||
def get_profile(route_ids):
|
def get_profile(route_ids):
|
||||||
route_ids = tuple(set(route_ids))
|
route_ids = tuple(set(route_ids))
|
||||||
profile = route2profile.get(route_ids)
|
profile = route2profile.get(route_ids)
|
||||||
if not profile:
|
if not profile:
|
||||||
profile_name = ""
|
profile_name = ""
|
||||||
route_names = [
|
route_names = [rec.name for rec in env["stock.route"].browse(route_ids)]
|
||||||
rec.name for rec in env["stock.location.route"].browse(route_ids)
|
|
||||||
]
|
|
||||||
profile_name = " / ".join(route_names)
|
profile_name = " / ".join(route_names)
|
||||||
profile = env["route.profile"].create(
|
profile = env["route.profile"].create(
|
||||||
{
|
{
|
||||||
@@ -26,13 +22,12 @@ def post_init_hook(cr, registry):
|
|||||||
route2profile[route_ids] = profile
|
route2profile[route_ids] = profile
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
||||||
query = """
|
query = """
|
||||||
SELECT product_id, array_agg(route_id)
|
SELECT product_id, array_agg(route_id)
|
||||||
FROM stock_route_product group by product_id;
|
FROM stock_route_product group by product_id;
|
||||||
"""
|
"""
|
||||||
cr.execute(query)
|
env.cr.execute(query)
|
||||||
results = cr.fetchall()
|
results = env.cr.fetchall()
|
||||||
route2profile = {}
|
route2profile = {}
|
||||||
profile2product = defaultdict(lambda: env["product.template"])
|
profile2product = defaultdict(lambda: env["product.template"])
|
||||||
for row in results:
|
for row in results:
|
||||||
|
|||||||
@@ -64,11 +64,24 @@ class ProductTemplate(models.Model):
|
|||||||
"route_ids": [(6, 0, self.route_ids.ids)],
|
"route_ids": [(6, 0, self.route_ids.ids)],
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model_create_multi
|
||||||
def create(self, vals):
|
def create(self, vals_list):
|
||||||
route_profile_id = vals.get("route_profile_id", False)
|
vals_with_profile = []
|
||||||
if route_profile_id:
|
vals_without_profile = []
|
||||||
route_profile = self.env["route.profile"].browse(route_profile_id)
|
for vals in vals_list:
|
||||||
vals["route_ids"] = [(6, 0, route_profile.route_ids.ids)]
|
route_profile_id = vals.get("route_profile_id")
|
||||||
self = self.with_context(skip_inverse_route_ids=True)
|
if route_profile_id:
|
||||||
return super(ProductTemplate, self).create(vals)
|
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
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ class RouteProfile(models.Model):
|
|||||||
comodel_name="res.company",
|
comodel_name="res.company",
|
||||||
default=lambda self: self.env.company.id,
|
default=lambda self: self.env.company.id,
|
||||||
required=False,
|
required=False,
|
||||||
string="Company",
|
|
||||||
)
|
)
|
||||||
route_ids = fields.Many2many(
|
route_ids = fields.Many2many(
|
||||||
"stock.location.route",
|
comodel_name="stock.route",
|
||||||
string="Routes",
|
string="Routes",
|
||||||
domain=[("product_selectable", "=", True)],
|
domain=[("product_selectable", "=", True)],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from odoo.tests.common import TransactionCase
|
|||||||
class TestProductRouteProfile(TransactionCase):
|
class TestProductRouteProfile(TransactionCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestProductRouteProfile, cls).setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
cls.company_bis = cls.env["res.company"].create(
|
cls.company_bis = cls.env["res.company"].create(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,16 +9,16 @@
|
|||||||
<field name="inherit_id" ref="product.product_template_form_view" />
|
<field name="inherit_id" ref="product.product_template_form_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='route_ids']/parent::div" position="attributes">
|
<xpath expr="//field[@name='route_ids']/parent::div" position="attributes">
|
||||||
<attribute name="attrs">{'invisible': True}</attribute>
|
<attribute name="invisible">True</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//group[@name='operations']" position="inside">
|
<xpath expr="//group[@name='operations']" position="inside">
|
||||||
<field
|
<field
|
||||||
name="route_profile_id"
|
name="route_profile_id"
|
||||||
attrs="{'invisible': [('type', 'in', ['service', 'digital'])]}"
|
invisible="type not in ['product', 'consu']"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="force_route_profile_id"
|
name="force_route_profile_id"
|
||||||
attrs="{'invisible': [('type', 'in', ['service', 'digital'])]}"
|
invisible="type not in ['product', 'consu']"
|
||||||
/>
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user