Skip to content

Commit 8af173c

Browse files
committed
[MIG] product_packaging_level: Migration to 17.0
1 parent b87a841 commit 8af173c

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

product_packaging_level/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Product Packaging Level",
6-
"version": "16.0.1.2.0",
6+
"version": "17.0.1.0.0",
77
"development_status": "Beta",
88
"category": "Product",
99
"summary": "This module binds a product packaging to a packaging level",

product_packaging_level/hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from odoo import SUPERUSER_ID, api
66

77

8-
def pre_init_hook(cr):
9-
if openupgrade.table_exists(cr, "product_packaging_type"):
10-
env = api.Environment(cr, SUPERUSER_ID, {})
8+
def pre_init_hook(env):
9+
if openupgrade.table_exists(env.cr, "product_packaging_type"):
10+
env = api.Environment(env.cr, SUPERUSER_ID, {})
1111
# Former version of the module is present
1212
models = [("product.packaging.type", "product.packaging.level")]
1313
openupgrade.rename_models(env.cr, models)

product_packaging_level/models/product_packaging_level.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ProductPackagingLevel(models.Model):
1010
_order = "sequence, code"
1111

1212
def _default_language(self):
13-
lang_code = self.env["ir.default"].get("res.partner", "lang")
13+
lang_code = self.env["ir.default"]._get("res.partner", "lang")
1414
def_lang_id = self.env["res.lang"]._lang_get_id(lang_code)
1515
return def_lang_id or self._active_languages()[0]
1616

@@ -66,8 +66,8 @@ def _check_is_default(self):
6666
if msg:
6767
raise ValidationError(msg)
6868

69-
def name_get(self):
70-
result = []
71-
for record in self:
72-
result.append((record.id, f"{record.name} ({record.code})"))
73-
return result
69+
@api.depends("name", "code")
70+
def _compute_display_name(self):
71+
for product_packaging_level in self:
72+
name = f"{product_packaging_level.name} ({product_packaging_level.code})"
73+
product_packaging_level.display_name = name

product_packaging_level/tests/test_product_packaging_level.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,26 @@ def setUpClass(cls):
3131
)
3232
cls.level_fr.with_context(lang="fr_FR").name = "Packaging Level Test France"
3333
cls.packaging_default = cls.env["product.packaging"].create(
34-
{"name": "Packaging Default", "qty": 1.0}
34+
{
35+
"name": "Packaging Default",
36+
"qty": 1.0,
37+
"product_id": cls.env.ref("product.product_product_5").id,
38+
}
3539
)
3640
cls.packaging = cls.env["product.packaging"].create(
37-
{"name": "Packaging Test", "packaging_level_id": cls.level.id, "qty": 1.0}
41+
{
42+
"name": "Packaging Test",
43+
"packaging_level_id": cls.level.id,
44+
"qty": 1.0,
45+
"product_id": cls.env.ref("product.product_product_5").id,
46+
}
3847
)
3948
cls.packaging_fr = cls.env["product.packaging"].create(
4049
{
4150
"name": "Packaging Test",
4251
"packaging_level_id": cls.level_fr.id,
4352
"qty": 1.0,
53+
"product_id": cls.env.ref("product.product_product_5").id,
4454
}
4555
)
4656
cls.product = cls.env["product.template"].create(

product_packaging_level/views/product_packaging_view.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
<field name="barcode_required_for_gtin" invisible="1" />
1616
</field>
1717
<xpath expr="//field[@name='barcode']" position="attributes">
18-
<attribute
19-
name="attrs"
20-
>{'required': [('barcode_required_for_gtin', '=', True)]}</attribute>
18+
<attribute name="required">barcode_required_for_gtin</attribute>
2119
</xpath>
2220
<field name="name" position="attributes">
23-
<attribute name="invisible">1</attribute>
21+
<attribute name="column_invisible">1</attribute>
2422
</field>
2523

2624
</field>
@@ -46,15 +44,11 @@
4644
<field name="barcode_required_for_gtin" invisible="1" />
4745
</xpath>
4846
<xpath expr="//field[@name='barcode']" position="attributes">
49-
<attribute
50-
name="attrs"
51-
>{'required': [('barcode_required_for_gtin', '=', True)]}</attribute>
47+
<attribute name="required">barcode_required_for_gtin</attribute>
5248
</xpath>
5349
<field name="name" position="attributes">
5450
<attribute name="force_save">1</attribute>
55-
<attribute
56-
name="attrs"
57-
>{'readonly': [('name_policy', '!=', 'user_defined')]}</attribute>
51+
<attribute name="readonly">name_policy != 'user_defined'</attribute>
5852
</field>
5953

6054
</field>

0 commit comments

Comments
 (0)