From 98c483515b1b27b77dfab86b1d833bfc942fa51b Mon Sep 17 00:00:00 2001 From: RabbitJon-S73 Date: Mon, 27 Feb 2023 10:16:19 +0100 Subject: [PATCH] [MIG] product_net_weight: Migration to 16.0 --- product_net_weight/__manifest__.py | 4 +- .../tests/test_product_net_weight.py | 70 +++++++++++++++++++ .../views/view_product_product.xml | 13 ++++ .../views/view_product_template.xml | 9 ++- .../odoo/addons/product_net_weight | 1 + setup/product_net_weight/setup.py | 6 ++ 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 product_net_weight/tests/test_product_net_weight.py create mode 120000 setup/product_net_weight/odoo/addons/product_net_weight create mode 100644 setup/product_net_weight/setup.py diff --git a/product_net_weight/__manifest__.py b/product_net_weight/__manifest__.py index 83e11a007fb..4aefab7f2db 100644 --- a/product_net_weight/__manifest__.py +++ b/product_net_weight/__manifest__.py @@ -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", diff --git a/product_net_weight/tests/test_product_net_weight.py b/product_net_weight/tests/test_product_net_weight.py new file mode 100644 index 00000000000..f9b196e792b --- /dev/null +++ b/product_net_weight/tests/test_product_net_weight.py @@ -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} + ) diff --git a/product_net_weight/views/view_product_product.xml b/product_net_weight/views/view_product_product.xml index dda47f1d9fd..a9e371d8c2d 100644 --- a/product_net_weight/views/view_product_product.xml +++ b/product_net_weight/views/view_product_product.xml @@ -19,5 +19,18 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + product.product + + + + + + diff --git a/product_net_weight/views/view_product_template.xml b/product_net_weight/views/view_product_template.xml index d4e82e892f0..07d3058fa04 100644 --- a/product_net_weight/views/view_product_template.xml +++ b/product_net_weight/views/view_product_template.xml @@ -8,9 +8,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). product.template - + - + diff --git a/setup/product_net_weight/odoo/addons/product_net_weight b/setup/product_net_weight/odoo/addons/product_net_weight new file mode 120000 index 00000000000..febcd09e3c3 --- /dev/null +++ b/setup/product_net_weight/odoo/addons/product_net_weight @@ -0,0 +1 @@ +../../../../product_net_weight \ No newline at end of file diff --git a/setup/product_net_weight/setup.py b/setup/product_net_weight/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_net_weight/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)