diff --git a/fermente_custom_import_demo/__manifest__.py b/fermente_custom_import_demo/__manifest__.py index 0b0340a..59d6597 100644 --- a/fermente_custom_import_demo/__manifest__.py +++ b/fermente_custom_import_demo/__manifest__.py @@ -14,11 +14,13 @@ # OCA "account_product_fiscal_classification", "l10n_fr_department_product_origin", + "product_net_weight", "product_origin", "product_supplierinfo_qty_multiplier", "purchase_discount", "purchase_triple_discount", # GRAP + "product_label", "fermente_custom_import_base", "fermente_custom_import_product", ], diff --git a/fermente_custom_import_product_label/README.rst b/fermente_custom_import_product_label/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/fermente_custom_import_product_label/__init__.py b/fermente_custom_import_product_label/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/fermente_custom_import_product_label/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fermente_custom_import_product_label/__manifest__.py b/fermente_custom_import_product_label/__manifest__.py new file mode 100644 index 0000000..b211fa0 --- /dev/null +++ b/fermente_custom_import_product_label/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "GRAP - Custom Product Import - Product Label Module", + "summary": "Extra GRAP Tools to import product data for" " Product Label module", + "version": "16.0.1.0.0", + "category": "Tools", + "author": "GRAP", + "website": "https://github.com/grap/grap-odoo-import", + "license": "AGPL-3", + "depends": ["fermente_custom_import_product", "product_label"], + "auto_install": True, + "installable": True, +} diff --git a/fermente_custom_import_product_label/models/__init__.py b/fermente_custom_import_product_label/models/__init__.py new file mode 100644 index 0000000..84c7d0c --- /dev/null +++ b/fermente_custom_import_product_label/models/__init__.py @@ -0,0 +1,2 @@ +from . import custom_import_product_mixin +from . import product_template diff --git a/fermente_custom_import_product_label/models/custom_import_product_mixin.py b/fermente_custom_import_product_label/models/custom_import_product_mixin.py new file mode 100644 index 0000000..c413748 --- /dev/null +++ b/fermente_custom_import_product_label/models/custom_import_product_mixin.py @@ -0,0 +1,24 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class CustomImportProductMixin(models.AbstractModel): + _name = "custom.import.product.mixin" + _inherit = ["custom.import.product.mixin"] + + # pylint: disable=missing-return + def _custom_import_hook_vals(self, old_vals, new_vals): + super()._custom_import_hook_vals(old_vals, new_vals) + self._custom_import_handle_product_label_vals(old_vals, new_vals) + + def _custom_import_handle_product_label_vals(self, old_vals, new_vals): + label_ids = [] + for x in range(1, 4): + field_name = f"grap_import_label_{x}" + if old_vals.get(field_name, False): + label_ids.append(old_vals[field_name]) + new_vals["label_ids"] = [(6, 0, label_ids)] + # new_vals["label_ids"] = [Command.link(label_ids)] diff --git a/fermente_custom_import_product_label/models/product_template.py b/fermente_custom_import_product_label/models/product_template.py new file mode 100644 index 0000000..7a3cd98 --- /dev/null +++ b/fermente_custom_import_product_label/models/product_template.py @@ -0,0 +1,21 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + grap_import_label_1 = fields.Many2one( + comodel_name="product.label", string="Label 1 (For import)", store=False + ) + + grap_import_label_2 = fields.Many2one( + comodel_name="product.label", string="Label 2 (For import)", store=False + ) + + grap_import_label_3 = fields.Many2one( + comodel_name="product.label", string="Label 3 (For import)", store=False + ) diff --git a/fermente_custom_import_product_label/readme/CONTRIBUTORS.rst b/fermente_custom_import_product_label/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..9f76a75 --- /dev/null +++ b/fermente_custom_import_product_label/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/fermente_custom_import_product_label/readme/DESCRIPTION.rst b/fermente_custom_import_product_label/readme/DESCRIPTION.rst new file mode 100644 index 0000000..8b7cd8d --- /dev/null +++ b/fermente_custom_import_product_label/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module improve the "import" features provided by Odoo. + +* ``product.product``: + + * Allow to recover ``discount`` field in the supplier info level. diff --git a/fermente_custom_import_product_label/tests/__init__.py b/fermente_custom_import_product_label/tests/__init__.py new file mode 100644 index 0000000..d9b96c4 --- /dev/null +++ b/fermente_custom_import_product_label/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/fermente_custom_import_product_label/tests/templates/product/product.csv b/fermente_custom_import_product_label/tests/templates/product/product.csv new file mode 100644 index 0000000..ce787f5 --- /dev/null +++ b/fermente_custom_import_product_label/tests/templates/product/product.csv @@ -0,0 +1,3 @@ +name,uom_id,categ_id,grap_import_label_1,grap_import_label_2,grap_import_label_3 +Product 1,Units,All / Saleable,Organic Food,Gluten Free, +Product 2,Units,All / Saleable,,,Max Havelaar diff --git a/fermente_custom_import_product_label/tests/test_module.py b/fermente_custom_import_product_label/tests/test_module.py new file mode 100644 index 0000000..2f43bfd --- /dev/null +++ b/fermente_custom_import_product_label/tests/test_module.py @@ -0,0 +1,44 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import tagged + +from odoo.addons.fermente_custom_import_product.tests.test_module import ( + TestModuleProduct, +) + + +@tagged("post_install", "-at_install") +class TestModulePurchaseDiscount(TestModuleProduct): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ProductProduct = cls.env["product.product"] + cls.label_organic = cls.env.ref("product_label.label_agriculture_biologique") + cls.label_gluten_free = cls.env.ref("product_label.label_gluten_free") + cls.label_max_havelaar = cls.env.ref("product_label.label_max_havelaar") + + def _test_import_product_label(self, model): + products, messages = self._test_import_file( + "fermente_custom_import_product_label", + model, + "product.csv", + folder="product", + ) + self.assertFalse(messages) + self.assertEqual(len(products), 2) + + product_1 = products.filtered(lambda x: x.name == "Product 1") + self.assertEqual( + product_1.label_ids, self.label_organic | self.label_gluten_free + ) + + product_2 = products.filtered(lambda x: x.name == "Product 2") + self.assertEqual(product_2.label_ids, self.label_max_havelaar) + + def test_01_import_product_label_product(self): + self._test_import_product_label("product.product") + + def test_02_import_product_label_template(self): + self._test_import_product_label("product.template") diff --git a/setup/fermente_custom_import_product_label/odoo/addons/fermente_custom_import_product_label b/setup/fermente_custom_import_product_label/odoo/addons/fermente_custom_import_product_label new file mode 120000 index 0000000..32a53c2 --- /dev/null +++ b/setup/fermente_custom_import_product_label/odoo/addons/fermente_custom_import_product_label @@ -0,0 +1 @@ +../../../../fermente_custom_import_product_label \ No newline at end of file diff --git a/setup/fermente_custom_import_product_label/setup.py b/setup/fermente_custom_import_product_label/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/fermente_custom_import_product_label/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt index e69de29..754ee7d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +# grap/grap-odoo-business +git+https://github.com/grap/grap-odoo-business@16.0#subdirectory=setup/product_label