Skip to content

Commit

Permalink
[IMP] product_dimension: Allow to create product template with dimens…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
rousseldenis committed Nov 23, 2022
1 parent 08cccaf commit 36e6216
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
15 changes: 15 additions & 0 deletions product_dimension/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ def convert_to_meters(self, measure, dimensional_uom):
to_unit=uom_meters,
round=False,
)

def _prepare_variant_values(self, combination):
"""
As variant is created inside template create() method and as
template fields values are flushed after _create_variant_ids(),
we catch the variant values preparation to update them
"""
res = super()._prepare_variant_values(combination)
if self.product_length:
res.update({"product_length": self.product_length})
if self.product_height:
res.update({"product_height": self.product_height})
if self.product_width:
res.update({"product_width": self.product_width})
return res
2 changes: 1 addition & 1 deletion product_dimension/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_compute_volume
from . import test_compute_volume, test_template
38 changes: 38 additions & 0 deletions product_dimension/tests/test_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase


class TestTemplateValues(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.product_template = cls.env["product.template"].create(
{
"name": "Unittest P1",
"product_length": 10.0,
"product_width": 5.0,
"product_height": 3.0,
"uom_id": cls.env.ref("uom.product_uom_unit").id,
"type": "consu",
}
)

def test_template(self):
"""
Data:
one product template with dimensions
Test Case:
get the product associated to the product_template and
check that the length, width and height
are the same as for the product template
Expected result:
length, width, height are the same on the product and product template
"""

product = self.product_template.product_variant_ids

self.assertEqual(product.product_length, 10.0)
self.assertEqual(product.product_width, 5.0)
self.assertEqual(product.product_height, 3.0)

0 comments on commit 36e6216

Please sign in to comment.