diff --git a/rotordc_autofill_product_variant/README.rst b/rotordc_autofill_product_variant/README.rst new file mode 100644 index 00000000..33a577a9 --- /dev/null +++ b/rotordc_autofill_product_variant/README.rst @@ -0,0 +1,67 @@ +================================ +RotorDC Autofill Product Variant +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:eb3e699ce4159790c7fe6b9f8e43609e1af22231b6907430800a925d10e691c8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-coopiteasy%2Fcie--custom-lightgray.png?logo=github + :target: https://github.com/coopiteasy/cie-custom/tree/16.0/rotordc_autofill_product_variant + :alt: coopiteasy/cie-custom + +|badge1| |badge2| |badge3| + +Autofill the following field when creating a new product variant based +on fields of the product template : + +* Internal reference +* Weight +* Dimensions (from product_dimension module) + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Coop IT Easy SC `_: + + * Rémy Taymans + +Maintainers +~~~~~~~~~~~ + +This module is part of the `coopiteasy/cie-custom `_ project on GitHub. + +You are welcome to contribute. diff --git a/rotordc_autofill_product_variant/__init__.py b/rotordc_autofill_product_variant/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/rotordc_autofill_product_variant/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rotordc_autofill_product_variant/__manifest__.py b/rotordc_autofill_product_variant/__manifest__.py new file mode 100644 index 00000000..3f3db3fa --- /dev/null +++ b/rotordc_autofill_product_variant/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2022 Coop IT Easy SC +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "RotorDC Autofill Product Variant", + "summary": """Autofill some field of the product variant based on + the product template.""", + "version": "16.0.1.0.0", + "category": "Uncategorized", + "website": "https://coopiteasy.be", + "author": "Coop IT Easy SC", + "license": "AGPL-3", + "application": False, + "depends": [ + "product", + "product_dimension", + ], + "excludes": [], + "data": [], + "demo": [], + "qweb": [], +} diff --git a/rotordc_autofill_product_variant/i18n/rotordc_autofill_product_variant.pot b/rotordc_autofill_product_variant/i18n/rotordc_autofill_product_variant.pot new file mode 100644 index 00000000..4775290b --- /dev/null +++ b/rotordc_autofill_product_variant/i18n/rotordc_autofill_product_variant.pot @@ -0,0 +1,20 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * rotordc_autofill_product_variant +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: rotordc_autofill_product_variant +#: model:ir.model,name:rotordc_autofill_product_variant.model_product_product +msgid "Product" +msgstr "" + diff --git a/rotordc_autofill_product_variant/models/__init__.py b/rotordc_autofill_product_variant/models/__init__.py new file mode 100644 index 00000000..e8fa8f6b --- /dev/null +++ b/rotordc_autofill_product_variant/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/rotordc_autofill_product_variant/models/product_template.py b/rotordc_autofill_product_variant/models/product_template.py new file mode 100644 index 00000000..3a089486 --- /dev/null +++ b/rotordc_autofill_product_variant/models/product_template.py @@ -0,0 +1,21 @@ +# Copyright 2022 Coop IT Easy SCRL fs +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _prepare_variant_values(self, combination): + """ + See explanation in the same method in the product_dimension module. + """ + res = super()._prepare_variant_values(combination) + if self.default_code: + res.update({"default_code": self.default_code}) + if self.weight: + res.update({"weight": self.weight}) + # product_dimension attributes are automatically copied by the + # product_dimension module. + return res diff --git a/rotordc_autofill_product_variant/readme/CONTRIBUTORS.rst b/rotordc_autofill_product_variant/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..31498d26 --- /dev/null +++ b/rotordc_autofill_product_variant/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SC `_: + + * Rémy Taymans diff --git a/rotordc_autofill_product_variant/readme/DESCRIPTION.rst b/rotordc_autofill_product_variant/readme/DESCRIPTION.rst new file mode 100644 index 00000000..082be50a --- /dev/null +++ b/rotordc_autofill_product_variant/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +Autofill the following field when creating a new product variant based +on fields of the product template : + +* Internal reference +* Weight +* Dimensions (from product_dimension module) diff --git a/rotordc_autofill_product_variant/static/description/index.html b/rotordc_autofill_product_variant/static/description/index.html new file mode 100644 index 00000000..fd578e0c --- /dev/null +++ b/rotordc_autofill_product_variant/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +RotorDC Autofill Product Variant + + + +
+

RotorDC Autofill Product Variant

+ + +

Beta License: AGPL-3 coopiteasy/cie-custom

+

Autofill the following field when creating a new product variant based +on fields of the product template :

+
    +
  • Internal reference
  • +
  • Weight
  • +
  • Dimensions (from product_dimension module)
  • +
+

Table of contents

+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Coop IT Easy SC
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the coopiteasy/cie-custom project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/rotordc_autofill_product_variant/tests/__init__.py b/rotordc_autofill_product_variant/tests/__init__.py new file mode 100644 index 00000000..99a3f5a5 --- /dev/null +++ b/rotordc_autofill_product_variant/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_product diff --git a/rotordc_autofill_product_variant/tests/test_product_product.py b/rotordc_autofill_product_variant/tests/test_product_product.py new file mode 100644 index 00000000..ba44f169 --- /dev/null +++ b/rotordc_autofill_product_variant/tests/test_product_product.py @@ -0,0 +1,144 @@ +# Copyright 2022 Coop IT Easy SCRL fs +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import odoo.tests.common as common +from odoo import fields + + +class TestProductProduct(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_product_10 = cls.env.ref("product.product_product_10") + cls.product_tmpl_10 = cls.product_product_10.product_tmpl_id + cls.product_attribute_1 = cls.env.ref("product.product_attribute_1") + cls.product_attribute_2 = cls.env.ref("product.product_attribute_2") + # Value for product_attribute_1 + cls.product_attribute_value_11 = cls.env.ref( + "product.product_attribute_value_1" + ) + cls.product_attribute_value_12 = cls.env.ref( + "product.product_attribute_value_2" + ) + # Value for product_attribute_2 + cls.product_attribute_value_21 = cls.env.ref( + "product.product_attribute_value_3" + ) + cls.product_attribute_value_22 = cls.env.ref( + "product.product_attribute_value_4" + ) + + cls.default_code = "AAA" + cls.weight = 50.0 + cls.product_length = 2.0 + cls.product_width = 1.0 + cls.product_height = 1.0 + + def _set_value_on_product_tmpl( + self, default_code, weight, product_length, product_width, product_height + ): + self.product_tmpl_10.write( + { + "default_code": default_code, + "weight": weight, + "product_length": product_length, + "product_width": product_width, + "product_height": product_height, + } + ) + + def test_autofill_when_creating_new_variant(self): + self._set_value_on_product_tmpl( + default_code=self.default_code, + weight=self.weight, + product_length=self.product_length, + product_width=self.product_width, + product_height=self.product_height, + ) + self.product_tmpl_10.write( + { + "attribute_line_ids": [ + fields.Command.create( + { + "attribute_id": self.product_attribute_1.id, + "value_ids": [ + fields.Command.set( + [ + self.product_attribute_value_11.id, + self.product_attribute_value_12.id, + ], + ), + ], + }, + ), + fields.Command.create( + { + "attribute_id": self.product_attribute_2.id, + "value_ids": [ + fields.Command.set( + [ + self.product_attribute_value_21.id, + self.product_attribute_value_22.id, + ], + ), + ], + }, + ), + ] + } + ) + + for product in self.product_tmpl_10.product_variant_ids: + self.assertEqual(product.default_code, self.default_code) + self.assertEqual(product.weight, self.weight) + self.assertEqual(product.product_length, self.product_length) + self.assertEqual(product.product_width, self.product_width) + self.assertEqual(product.product_height, self.product_height) + + def test_autofill_for_new_template(self): + product_template = self.env["product.template"].create( + { + "name": "New product", + "default_code": self.default_code, + "weight": self.weight, + "product_length": self.product_length, + "product_width": self.product_width, + "product_height": self.product_height, + } + ) + for product in product_template.product_variant_ids: + self.assertEqual(product.default_code, self.default_code) + self.assertEqual(product.weight, self.weight) + self.assertEqual(product.product_length, self.product_length) + self.assertEqual(product.product_width, self.product_width) + self.assertEqual(product.product_height, self.product_height) + + product_template.write( + { + "attribute_line_ids": [ + [ + 0, + 0, + { + "attribute_id": self.product_attribute_1.id, + "value_ids": [ + [ + 6, + 0, + [ + self.product_attribute_value_11.id, + self.product_attribute_value_12.id, + ], + ] + ], + }, + ], + ] + } + ) + for product in product_template.product_variant_ids: + self.assertEqual(product.default_code, self.default_code) + self.assertEqual(product.weight, self.weight) + self.assertEqual(product.product_length, self.product_length) + self.assertEqual(product.product_width, self.product_width) + self.assertEqual(product.product_height, self.product_height) diff --git a/setup/rotordc_autofill_product_variant/odoo/addons/rotordc_autofill_product_variant b/setup/rotordc_autofill_product_variant/odoo/addons/rotordc_autofill_product_variant new file mode 120000 index 00000000..b62d1b50 --- /dev/null +++ b/setup/rotordc_autofill_product_variant/odoo/addons/rotordc_autofill_product_variant @@ -0,0 +1 @@ +../../../../rotordc_autofill_product_variant \ No newline at end of file diff --git a/setup/rotordc_autofill_product_variant/setup.py b/setup/rotordc_autofill_product_variant/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/rotordc_autofill_product_variant/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)