diff --git a/product_secondary_unit/README.rst b/product_secondary_unit/README.rst index 3dd6c662a35d..20343db19fbd 100644 --- a/product_secondary_unit/README.rst +++ b/product_secondary_unit/README.rst @@ -17,13 +17,13 @@ Product Secondary Unit :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github - :target: https://github.com/OCA/product-attribute/tree/17.0/product_secondary_unit + :target: https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit :alt: OCA/product-attribute .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_secondary_unit + :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_secondary_unit :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=17.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -51,7 +51,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -66,11 +66,11 @@ Authors Contributors ------------ -- Carlos Dauden -- Sergio Teruel -- Kitti Upariphutthiphong -- Pimolnat Suntian -- Alan Ramos +- Carlos Dauden +- Sergio Teruel +- Kitti Upariphutthiphong +- Pimolnat Suntian +- Alan Ramos Maintainers ----------- @@ -93,6 +93,6 @@ Current `maintainer `__: |maintainer-sergio-teruel| -This module is part of the `OCA/product-attribute `_ project on GitHub. +This module is part of the `OCA/product-attribute `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_secondary_unit/__manifest__.py b/product_secondary_unit/__manifest__.py index 19ca23ff3804..bb474590594c 100644 --- a/product_secondary_unit/__manifest__.py +++ b/product_secondary_unit/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Product Secondary Unit", "summary": "Set a secondary unit per product", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "development_status": "Production/Stable", "category": "Product", "website": "https://github.com/OCA/product-attribute", diff --git a/product_secondary_unit/static/description/index.html b/product_secondary_unit/static/description/index.html index c64a2eeec3d7..28a21f763ed6 100644 --- a/product_secondary_unit/static/description/index.html +++ b/product_secondary_unit/static/description/index.html @@ -369,7 +369,7 @@

Product Secondary Unit

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:3038be23ebd37dd87f7595ccf86308fa611b0a81df5134e31c81d12bb79f3f84 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Production/Stable License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

+

Production/Stable License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

This module extends the functionality of product module to allow define other units with their conversion factor.

Table of contents

@@ -399,7 +399,7 @@

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -431,7 +431,7 @@

Maintainers

promote its widespread use.

Current maintainer:

sergio-teruel

-

This module is part of the OCA/product-attribute project on GitHub.

+

This module is part of the OCA/product-attribute project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/product_secondary_unit/tests/test_product_second_unit.py b/product_secondary_unit/tests/test_product_second_unit.py index cb7b070e93b7..3bde2265e5aa 100644 --- a/product_secondary_unit/tests/test_product_second_unit.py +++ b/product_secondary_unit/tests/test_product_second_unit.py @@ -1,7 +1,12 @@ # Copyright 2018 Tecnativa - Sergio Teruel # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging + +from odoo.fields import Command from odoo.tests import TransactionCase, tagged +_logger = logging.getLogger(__name__) + @tagged("post_install", "-at_install") class TestProductSecondaryUnit(TransactionCase): @@ -39,9 +44,69 @@ def setUpClass(cls): ], } ) + cls.woods = cls.env["product.template"].create( + { + "name": "Piece of woods", + "list_price": 2000, + "uom_id": cls.product_uom_kg.id, + "uom_po_id": cls.product_uom_kg.id, + "secondary_uom_ids": [ + ( + 0, + 0, + { + "code": "A", + "name": "unit-700", + "uom_id": cls.product_uom_unit.id, + "factor": 0.7, + }, + ), + ( + 0, + 0, + { + "code": "B", + "name": "unit-900", + "uom_id": cls.product_uom_unit.id, + "factor": 0.9, + }, + ), + ], + } + ) cls.secondary_unit = cls.env["product.secondary.unit"].search( [("product_tmpl_id", "=", cls.product.id)], limit=1 ) + cls.densitiy = cls.env["product.attribute"].create( + [ + { + "name": "Density", + "sequence": 1, + "value_ids": [ + Command.create( + { + "name": "Low", + "sequence": 1, + } + ), + Command.create( + { + "name": "Heavy", + "sequence": 2, + } + ), + ], + } + ] + ) + cls.low, cls.heavy = cls.densitiy.value_ids + cls.density_attribute_lines = cls.env["product.template.attribute.line"].create( + { + "product_tmpl_id": cls.woods.id, + "attribute_id": cls.densitiy.id, + "value_ids": [Command.set([cls.low.id, cls.heavy.id])], + } + ) def test_product_secondary_unit_name(self): self.assertEqual(self.secondary_unit.name_get()[0][1], "unit-700-0.7") @@ -58,3 +123,36 @@ def test_product_secondary_unit_search(self): self.assertEqual(len(name_get), 1) name_get = self.env["product.secondary.unit"].name_search(name="X", args=args) self.assertEqual(len(name_get), 0) + + def test_multi_variant_product_secondary_unit(self): + first_variant = self.woods.product_variant_ids[0] + second_variant = self.woods.product_variant_ids[1] + self.assertEqual(len(self.woods.secondary_uom_ids), 2) + self.assertEqual(first_variant.secondary_uom_ids, self.woods.secondary_uom_ids) + + first_variant.write( + { + "secondary_uom_ids": [ + ( + 0, + 0, + { + "code": "C", + "name": "unit-1000", + "product_id": first_variant.id, + "uom_id": self.product_uom_unit.id, + "factor": 0.1, + }, + ), + ] + } + ) + _logger.info( + f"Template 2Uoms: {self.woods.secondary_uom_ids.mapped('name')}" + f" -- Product var1 2Uoms: {first_variant.secondary_uom_ids.mapped('name')}" + f" -- Product var2 2Uoms: {second_variant.secondary_uom_ids.mapped('name')}" + ) + first_variant.invalidate_recordset() + self.assertEqual(len(self.woods.secondary_uom_ids), 3) + self.assertEqual(len(first_variant.secondary_uom_ids), 3) + self.assertEqual(len(second_variant.secondary_uom_ids), 2) diff --git a/product_secondary_unit/tests/test_secondary_unit_mixin.py b/product_secondary_unit/tests/test_secondary_unit_mixin.py index df27d26ad543..f804355a495e 100644 --- a/product_secondary_unit/tests/test_secondary_unit_mixin.py +++ b/product_secondary_unit/tests/test_secondary_unit_mixin.py @@ -43,11 +43,23 @@ def setUpClass(cls): "factor": 10, }, ), + ( + 0, + 0, + { + "code": "C20", + "name": "box 20", + "dependency_type": "independent", + "uom_id": cls.product_uom_unit.id, + "factor": 20, + }, + ), ], } ) cls.secondary_unit_box_5 = cls.product_template.secondary_uom_ids[0] cls.secondary_unit_box_10 = cls.product_template.secondary_uom_ids[1] + cls.secondary_unit_box_20 = cls.product_template.secondary_uom_ids[2] # Fake model which inherit from cls.secondary_unit_fake = cls.env["secondary.unit.fake"].create( { @@ -87,6 +99,21 @@ def test_product_secondary_unit_mixin(self): fake_model._onchange_helper_product_uom_for_secondary() self.assertEqual(fake_model.secondary_uom_qty, 12) + def test_product_secondary_unit_independent_mixin(self): + fake_model = self.secondary_unit_fake + fake_model.write( + { + "product_uom_qty": 20, + "secondary_uom_qty": 1, + "secondary_uom_id": self.secondary_unit_box_20.id, + } + ) + self.assertEqual(fake_model.product_uom_qty, 20) + fake_model.invalidate_recordset() + fake_model.product_uom_id = self.product_uom_dozen + fake_model._onchange_helper_product_uom_for_secondary() + self.assertEqual(fake_model.secondary_uom_qty, 1) + def test_product_secondary_unit_mixin_no_uom(self): # If secondary_uom_id is not informed product_qty on target model is # not computed. diff --git a/product_secondary_unit/views/product_views.xml b/product_secondary_unit/views/product_views.xml index fc44ab527336..3b74e26aa0ab 100644 --- a/product_secondary_unit/views/product_views.xml +++ b/product_secondary_unit/views/product_views.xml @@ -17,7 +17,7 @@ groups="uom.group_uom" > - + - + @@ -45,7 +45,7 @@ [('id', '=', parent.id)] diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000000..66bc2cbae3f9 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo_test_helper