forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] product_net_weight: Migration to 16.0
- Loading branch information
1 parent
3216d1f
commit 98c4835
Showing
6 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../product_net_weight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |