Skip to content

Commit

Permalink
[MIG] product_net_weight: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitJon-S73 authored and ferran-S73 committed Jun 7, 2023
1 parent 3216d1f commit 98c4835
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
4 changes: 2 additions & 2 deletions product_net_weight/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
{
"name": "Products - Net Weight",
"summary": "Add 'Net Weight' on product models",
"version": "15.0.1.0.2",
"version": "16.0.1.0.0",
"category": "Product",
"author": "GRAP,Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"depends": ["product"],
"depends": ["stock"],
"data": [
"views/view_product_product.xml",
"views/view_product_template.xml",
Expand Down
70 changes: 70 additions & 0 deletions product_net_weight/tests/test_product_net_weight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2023 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import Form, TransactionCase


class TestProductNetWeight(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.attribute = cls.env["product.attribute"].create(
{
"name": "test attribute",
"display_type": "select",
}
)

def test_create_product_template(self):
product_form = Form(self.env["product.template"])
product_form.name = "Test net weight"
product_form.net_weight = 25.0
product = product_form.save()
self.assertEqual(product.net_weight, 25.0)
self.assertEqual(product.product_variant_id.net_weight, 25.0)
product.write(
{
"attribute_line_ids": [
(
0,
0,
{
"attribute_id": self.attribute.id,
"value_ids": [
(
0,
0,
{
"attribute_id": self.attribute.id,
"name": "test value 1",
},
),
(
0,
0,
{
"attribute_id": self.attribute.id,
"name": "test value 2",
},
),
],
},
)
]
}
)
self.assertEqual(product.net_weight, 0.0)

def test_create_product_product(self):
product_form = Form(self.env["product.product"])
product_form.name = "Test net weight"
product_form.net_weight = 25.0
product = product_form.save()
self.assertEqual(product.net_weight, 25.0)
self.assertEqual(product.product_variant_id.net_weight, 25.0)

def test_product_constraint(self):
with self.assertRaises(ValidationError):
self.env["product.product"].create(
{"name": "Test net weight", "net_weight": 25.0, "weight": 22.0}
)
13 changes: 13 additions & 0 deletions product_net_weight/views/view_product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</xpath>
</field>
</record>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//label[@for='weight']" position="before">
<label for="net_weight" />
<div class="o_row">
<field name="net_weight" class="oe_inline" />
<span><field name="weight_uom_name" /></span>
</div>
</xpath>
</field>
</record>

</odoo>
9 changes: 6 additions & 3 deletions product_net_weight/views/view_product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

<record id="view_product_template_form" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field
name="inherit_id"
ref="stock.product_template_form_view_procurement_button"
/>
<field name="arch" type="xml">
<xpath expr="//label[@for='weight']" position="before">
<xpath expr="//field[@name='responsible_id']" position="after">
<label
for="net_weight"
attrs="{'invisible':[('product_variant_count', '&gt;', 1), ('is_product_variant', '=', False)]}"
Expand All @@ -20,7 +23,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
name="net_weight"
attrs="{'invisible':[('product_variant_count', '&gt;', 1), ('is_product_variant', '=', False)]}"
>
<field name="net_weight" />
<field name="net_weight" class="oe_inline" />
<span><field name="weight_uom_name" /></span>
</div>
</xpath>
Expand Down
1 change: 1 addition & 0 deletions setup/product_net_weight/odoo/addons/product_net_weight
6 changes: 6 additions & 0 deletions setup/product_net_weight/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 98c4835

Please sign in to comment.