From 2e25af72e5cfd5ecb1c7fe824b3937fa197141d3 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 19 Jan 2024 14:49:36 +0100 Subject: [PATCH] [ADD] New module grap_custom_import_product --- .../models/custom_import_mixin.py | 1 - grap_custom_import_product/README.rst | 0 grap_custom_import_product/__init__.py | 1 + grap_custom_import_product/__manifest__.py | 16 +++++ grap_custom_import_product/models/__init__.py | 1 + .../models/product_product.py | 58 +++++++++++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 7 +++ grap_custom_import_product/tests/__init__.py | 1 + .../templates/product.product/product.csv | 4 ++ .../tests/test_module.py | 23 ++++++++ .../odoo/addons/grap_custom_import_product | 1 + setup/grap_custom_import_product/setup.py | 6 ++ 13 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 grap_custom_import_product/README.rst create mode 100644 grap_custom_import_product/__init__.py create mode 100644 grap_custom_import_product/__manifest__.py create mode 100644 grap_custom_import_product/models/__init__.py create mode 100644 grap_custom_import_product/models/product_product.py create mode 100644 grap_custom_import_product/readme/CONTRIBUTORS.rst create mode 100644 grap_custom_import_product/readme/DESCRIPTION.rst create mode 100644 grap_custom_import_product/tests/__init__.py create mode 100644 grap_custom_import_product/tests/templates/product.product/product.csv create mode 100644 grap_custom_import_product/tests/test_module.py create mode 120000 setup/grap_custom_import_product/odoo/addons/grap_custom_import_product create mode 100644 setup/grap_custom_import_product/setup.py diff --git a/grap_custom_import_base/models/custom_import_mixin.py b/grap_custom_import_base/models/custom_import_mixin.py index 0ae61ec..8b155c7 100644 --- a/grap_custom_import_base/models/custom_import_mixin.py +++ b/grap_custom_import_base/models/custom_import_mixin.py @@ -16,7 +16,6 @@ def _custom_import_prevent_duplicate_fields(self): return [] def _custom_import_hook_vals(self, old_vals, new_vals): - # Check if existing duplicates are present in the database for field in self._custom_import_prevent_duplicate_fields(): if new_vals.get(field): diff --git a/grap_custom_import_product/README.rst b/grap_custom_import_product/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/grap_custom_import_product/__init__.py b/grap_custom_import_product/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/grap_custom_import_product/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/grap_custom_import_product/__manifest__.py b/grap_custom_import_product/__manifest__.py new file mode 100644 index 0000000..2604767 --- /dev/null +++ b/grap_custom_import_product/__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 Import Product Module", + "summary": "Extra GRAP Tools to import data for product module", + "version": "16.0.1.0.0", + "category": "Tools", + "author": "GRAP", + "website": "https://github.com/grap/grap-odoo-import", + "license": "AGPL-3", + "depends": ["grap_custom_import_base", "product"], + "auto_install": True, + "installable": True, +} diff --git a/grap_custom_import_product/models/__init__.py b/grap_custom_import_product/models/__init__.py new file mode 100644 index 0000000..5c74c8c --- /dev/null +++ b/grap_custom_import_product/models/__init__.py @@ -0,0 +1 @@ +from . import product_product diff --git a/grap_custom_import_product/models/product_product.py b/grap_custom_import_product/models/product_product.py new file mode 100644 index 0000000..bc507f5 --- /dev/null +++ b/grap_custom_import_product/models/product_product.py @@ -0,0 +1,58 @@ +# 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 ResPartner(models.Model): + _name = "product.product" + _inherit = ["product.product", "custom.import.mixin"] + + def _custom_import_prevent_duplicate_fields(self): + res = super()._custom_import_prevent_duplicate_fields() + res += ["name", "barcode"] + return res + + grap_import_supplier_name = fields.Char( + string="Supplier Name (For import)", store=False + ) + grap_import_supplier_product_code = fields.Char( + string="Product Code - Supplier (For import)", store=False + ) + grap_import_supplier_product_name = fields.Char( + string="Product Name - Supplier (For import)", store=False + ) + grap_import_supplier_min_qty = fields.Monetary( + string="Product Min Quantity - Supplier (For import)", store=False + ) + grap_import_supplier_gross_price = fields.Monetary( + string="Product Gross Price - Supplier (For import)", store=False + ) + + # 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_supplierinfo_vals(old_vals, new_vals) + + def _custom_import_handle_supplierinfo_vals(self, old_vals, new_vals): + supplier = self._custom_import_get_or_create( + "res.partner", "name", old_vals, "grap_import_supplier_name" + ) + if supplier: + new_vals["seller_ids"] = [ + ( + 0, + False, + self._custom_import_prepare_supplierinfo_vals(supplier, old_vals), + ) + ] + + def _custom_import_prepare_supplierinfo_vals(self, partner, vals): + return { + "partner_id": partner.id, + "price": vals.get("grap_import_supplier_gross_price"), + "product_code": vals.get("grap_import_supplier_product_code"), + "product_name": vals.get("grap_import_supplier_product_name"), + "min_qty": vals.get("grap_import_supplier_min_qty"), + } diff --git a/grap_custom_import_product/readme/CONTRIBUTORS.rst b/grap_custom_import_product/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..9f76a75 --- /dev/null +++ b/grap_custom_import_product/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/grap_custom_import_product/readme/DESCRIPTION.rst b/grap_custom_import_product/readme/DESCRIPTION.rst new file mode 100644 index 0000000..2a7a089 --- /dev/null +++ b/grap_custom_import_product/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module improve the "import" features provided by Odoo. + +It provides generic tools for that purpose, and improve imports for some models. + +* ``res.partner``: + + * Prevent to create duplicates regarding ``name`` and ``vat`` fields. \ No newline at end of file diff --git a/grap_custom_import_product/tests/__init__.py b/grap_custom_import_product/tests/__init__.py new file mode 100644 index 0000000..d9b96c4 --- /dev/null +++ b/grap_custom_import_product/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/grap_custom_import_product/tests/templates/product.product/product.csv b/grap_custom_import_product/tests/templates/product.product/product.csv new file mode 100644 index 0000000..06be570 --- /dev/null +++ b/grap_custom_import_product/tests/templates/product.product/product.csv @@ -0,0 +1,4 @@ +name,uom_id,categ_id,barcode,list_price,grap_import_supplier_name,grap_import_supplier_product_code,grap_import_supplier_product_name,grap_import_supplier_gross_price +Coca Cola (Import),Units,All / Saleable / Office Furniture,5000112602791,4.12,Ready Mat,CC,BOTTLE 33CL,3.33 +Produit B,Units,All / Saleable / Office Furniture,,8.00,Supplier From Product Import,PB,product_B,6.00 +Produit C,Units,All / Saleable,,2.30,,,, diff --git a/grap_custom_import_product/tests/test_module.py b/grap_custom_import_product/tests/test_module.py new file mode 100644 index 0000000..aefaf5f --- /dev/null +++ b/grap_custom_import_product/tests/test_module.py @@ -0,0 +1,23 @@ +# 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.grap_custom_import_base.tests.test_module import TestModuleBase + + +@tagged("post_install", "-at_install") +class TestModuleProduct(TestModuleBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ProductProduct = cls.env["product.product"] + + def test_01_import_product(self): + products, messages = self._test_import_file( + "grap_custom_import_product", "product.product", "product.csv" + ) + self.assertFalse(messages) + self.assertEqual(len(products), 3) + self.assertIn("Coca Cola (Import)", products.mapped("name")) diff --git a/setup/grap_custom_import_product/odoo/addons/grap_custom_import_product b/setup/grap_custom_import_product/odoo/addons/grap_custom_import_product new file mode 120000 index 0000000..3a0e364 --- /dev/null +++ b/setup/grap_custom_import_product/odoo/addons/grap_custom_import_product @@ -0,0 +1 @@ +../../../../grap_custom_import_product \ No newline at end of file diff --git a/setup/grap_custom_import_product/setup.py b/setup/grap_custom_import_product/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/grap_custom_import_product/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)