diff --git a/fermente_custom_import_account_product_fiscal_classification/models/custom_import_product_mixin.py b/fermente_custom_import_account_product_fiscal_classification/models/custom_import_product_mixin.py index cc78acf..0724d20 100644 --- a/fermente_custom_import_account_product_fiscal_classification/models/custom_import_product_mixin.py +++ b/fermente_custom_import_account_product_fiscal_classification/models/custom_import_product_mixin.py @@ -11,10 +11,10 @@ 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_fiscal_classification_id(old_vals, new_vals) + return def _custom_import_fiscal_classification_domain(self, vat_amount): domain = expression.OR( diff --git a/fermente_custom_import_base/models/__init__.py b/fermente_custom_import_base/models/__init__.py index 79c0518..f97e652 100644 --- a/fermente_custom_import_base/models/__init__.py +++ b/fermente_custom_import_base/models/__init__.py @@ -1,2 +1,3 @@ from . import custom_import_mixin +from . import custom_import_partner_mixin from . import res_partner diff --git a/fermente_custom_import_base/models/custom_import_mixin.py b/fermente_custom_import_base/models/custom_import_mixin.py index 2507577..0b29145 100644 --- a/fermente_custom_import_base/models/custom_import_mixin.py +++ b/fermente_custom_import_base/models/custom_import_mixin.py @@ -31,6 +31,9 @@ def _custom_import_hook_vals(self, old_vals, new_vals): ) return new_vals + def _custom_import_hook_check(self, vals_list): + self._custom_import_check_duplicates_new_vals(vals_list) + def _custom_import_check_duplicates_new_vals(self, vals_list): for field in self._custom_import_prevent_duplicate_fields(): duplicates = [] @@ -85,7 +88,6 @@ def _load_records_create(self, vals_list): self._custom_import_hook_vals(vals, new_vals) new_vals_list.append(new_vals) - # TODO, move this check in another part - self._custom_import_check_duplicates_new_vals(new_vals_list) + self._custom_import_hook_check(new_vals_list) return super()._load_records_create(new_vals_list) diff --git a/fermente_custom_import_base/models/custom_import_partner_mixin.py b/fermente_custom_import_base/models/custom_import_partner_mixin.py new file mode 100644 index 0000000..8aac6fd --- /dev/null +++ b/fermente_custom_import_base/models/custom_import_partner_mixin.py @@ -0,0 +1,16 @@ +# 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 CustomImportPartnerMixin(models.AbstractModel): + _name = "custom.import.partner.mixin" + _description = "Abstract model to import partner (customer and supplier)" + _inherit = ["custom.import.mixin"] + + def _custom_import_prevent_duplicate_fields(self): + res = super()._custom_import_prevent_duplicate_fields() + res += ["name", "vat"] + return res diff --git a/fermente_custom_import_base/models/res_partner.py b/fermente_custom_import_base/models/res_partner.py index 4dcc46c..bda563a 100644 --- a/fermente_custom_import_base/models/res_partner.py +++ b/fermente_custom_import_base/models/res_partner.py @@ -11,9 +11,4 @@ class ResPartner(models.Model): _name = "res.partner" - _inherit = ["res.partner", "custom.import.mixin"] - - def _custom_import_prevent_duplicate_fields(self): - res = super()._custom_import_prevent_duplicate_fields() - res += ["name", "vat"] - return res + _inherit = ["res.partner", "custom.import.partner.mixin"] diff --git a/fermente_custom_import_base/tests/__init__.py b/fermente_custom_import_base/tests/__init__.py index d9b96c4..d1f30b7 100644 --- a/fermente_custom_import_base/tests/__init__.py +++ b/fermente_custom_import_base/tests/__init__.py @@ -1 +1,2 @@ from . import test_module +from . import test_module_partner diff --git a/fermente_custom_import_base/tests/test_module.py b/fermente_custom_import_base/tests/test_module.py index 5b58e4e..94a283c 100644 --- a/fermente_custom_import_base/tests/test_module.py +++ b/fermente_custom_import_base/tests/test_module.py @@ -20,8 +20,7 @@ def _test_import_file(self, module, model, file_name, folder=False): import_options = {"has_headers": True, "quoting": '"'} # Read File - if not folder: - folder = model + folder = folder and folder or model file_path = get_module_resource(module, "tests/templates/", folder, file_name) extension = file_path.split(".")[-1] if extension == "csv": @@ -45,41 +44,3 @@ def _test_import_file(self, module, model, file_name, folder=False): items = self.env[model].browse(results.get("ids")) return items, results["messages"] - - def test_01_import_supplier(self): - partners, messages = self._test_import_file( - "fermente_custom_import_base", "res.partner", "supplier.csv" - ) - self.assertFalse(messages) - self.assertEqual(len(partners), 1) - self.assertEqual(partners.name, "Relais Vert") - - def test_02_existing_duplicates_name(self): - partners, messages = self._test_import_file( - "fermente_custom_import_base", "res.partner", "supplier.csv" - ) - self.assertFalse(messages) - partners, messages = self._test_import_file( - "fermente_custom_import_base", "res.partner", "supplier.csv" - ) - self.assertEqual(len(messages), 1) - self.assertEqual(messages[0].get("type"), "error") - - def test_03_import_supplier_new_duplicates_vat(self): - partners, messages = self._test_import_file( - "fermente_custom_import_base", - "res.partner", - "supplier_new_duplicates_vat.csv", - ) - self.assertEqual(len(messages), 2) - self.assertEqual(messages[0].get("type"), "error") - self.assertEqual(messages[1].get("type"), "error") - - def test_04_import_supplier_existing_duplicates_vat(self): - partners, messages = self._test_import_file( - "fermente_custom_import_base", - "res.partner", - "supplier_existing_duplicates_vat.csv", - ) - self.assertEqual(len(messages), 1) - self.assertEqual(messages[0].get("type"), "error") diff --git a/fermente_custom_import_base/tests/test_module_partner.py b/fermente_custom_import_base/tests/test_module_partner.py new file mode 100644 index 0000000..93abcaa --- /dev/null +++ b/fermente_custom_import_base/tests/test_module_partner.py @@ -0,0 +1,48 @@ +# 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 .test_module import TestModuleBase + + +@tagged("post_install", "-at_install") +class TestModulePartner(TestModuleBase): + def test_01_import_supplier(self): + partners, messages = self._test_import_file( + "fermente_custom_import_base", "res.partner", "supplier.csv" + ) + self.assertFalse(messages) + self.assertEqual(len(partners), 1) + self.assertEqual(partners.name, "Relais Vert") + + def test_02_existing_duplicates_name(self): + partners, messages = self._test_import_file( + "fermente_custom_import_base", "res.partner", "supplier.csv" + ) + self.assertFalse(messages) + partners, messages = self._test_import_file( + "fermente_custom_import_base", "res.partner", "supplier.csv" + ) + self.assertEqual(len(messages), 1) + self.assertEqual(messages[0].get("type"), "error") + + def test_03_import_supplier_new_duplicates_vat(self): + partners, messages = self._test_import_file( + "fermente_custom_import_base", + "res.partner", + "supplier_new_duplicates_vat.csv", + ) + self.assertEqual(len(messages), 2) + self.assertEqual(messages[0].get("type"), "error") + self.assertEqual(messages[1].get("type"), "error") + + def test_04_import_supplier_existing_duplicates_vat(self): + partners, messages = self._test_import_file( + "fermente_custom_import_base", + "res.partner", + "supplier_existing_duplicates_vat.csv", + ) + self.assertEqual(len(messages), 1) + self.assertEqual(messages[0].get("type"), "error") diff --git a/fermente_custom_import_demo/static/xlsx/template_import.xlsx b/fermente_custom_import_demo/static/xlsx/template_import.xlsx new file mode 100644 index 0000000..eedb7d4 Binary files /dev/null and b/fermente_custom_import_demo/static/xlsx/template_import.xlsx differ diff --git a/fermente_custom_import_demo/static/xlsx/template_product.xlsx b/fermente_custom_import_demo/static/xlsx/template_product.xlsx deleted file mode 100644 index 7893274..0000000 Binary files a/fermente_custom_import_demo/static/xlsx/template_product.xlsx and /dev/null differ diff --git a/fermente_custom_import_partner_firstname/README.rst b/fermente_custom_import_partner_firstname/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/fermente_custom_import_partner_firstname/__init__.py b/fermente_custom_import_partner_firstname/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/fermente_custom_import_partner_firstname/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fermente_custom_import_partner_firstname/__manifest__.py b/fermente_custom_import_partner_firstname/__manifest__.py new file mode 100644 index 0000000..e655cec --- /dev/null +++ b/fermente_custom_import_partner_firstname/__manifest__.py @@ -0,0 +1,17 @@ +# 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 Partner Import - First Name Module", + "summary": "Extra GRAP Tools to import partner data for" + " Partner First Name 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_base", "partner_firstname"], + "auto_install": True, + "installable": True, +} diff --git a/fermente_custom_import_partner_firstname/models/__init__.py b/fermente_custom_import_partner_firstname/models/__init__.py new file mode 100644 index 0000000..103acf0 --- /dev/null +++ b/fermente_custom_import_partner_firstname/models/__init__.py @@ -0,0 +1 @@ +from . import custom_import_partner_mixin diff --git a/fermente_custom_import_partner_firstname/models/custom_import_partner_mixin.py b/fermente_custom_import_partner_firstname/models/custom_import_partner_mixin.py new file mode 100644 index 0000000..b4b5ac5 --- /dev/null +++ b/fermente_custom_import_partner_firstname/models/custom_import_partner_mixin.py @@ -0,0 +1,41 @@ +# 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 +from odoo.exceptions import ValidationError + + +class CustomImportPartnerMixin(models.AbstractModel): + _name = "custom.import.partner.mixin" + _inherit = ["custom.import.partner.mixin"] + + def _custom_import_hook_vals(self, old_vals, new_vals): + super()._custom_import_hook_vals(old_vals, new_vals) + self._custom_import_handle_company_type(old_vals, new_vals) + return + + def _custom_import_handle_company_type(self, old_vals, new_vals): + if old_vals.get("name"): + new_vals["company_type"] = "company" + else: + new_vals = "person" + + def _custom_import_hook_check(self, vals_list): + super()._custom_import_hook_check(vals_list) + for vals in vals_list: + if (vals.get("firstname") or vals.get("lastname")) and vals.get("name"): + raise ValidationError( + _( + "The file contains contacts that has first name or last name AND" + " name fields defined. Please set a name for a company" + " or a first name / last name for an individual." + " First Name: %(firstname)s ; " + " Last Name: %(lastname)s ; " + " Name: %(name)s", + name=vals.get("name"), + firstname=vals.get("firstname"), + lastname=vals.get("lastname"), + ) + ) + return diff --git a/fermente_custom_import_partner_firstname/readme/CONTRIBUTORS.rst b/fermente_custom_import_partner_firstname/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..9f76a75 --- /dev/null +++ b/fermente_custom_import_partner_firstname/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/fermente_custom_import_partner_firstname/readme/DESCRIPTION.rst b/fermente_custom_import_partner_firstname/readme/DESCRIPTION.rst new file mode 100644 index 0000000..b857a5a --- /dev/null +++ b/fermente_custom_import_partner_firstname/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module improve the "import" features provided by Odoo. + +* ``res.partner``: + + * If the name is set, the partner will be set as "Company", + otherwise, it will be set as "Individual". diff --git a/fermente_custom_import_partner_firstname/tests/__init__.py b/fermente_custom_import_partner_firstname/tests/__init__.py new file mode 100644 index 0000000..d9b96c4 --- /dev/null +++ b/fermente_custom_import_partner_firstname/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner.csv b/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner.csv new file mode 100644 index 0000000..a260afd --- /dev/null +++ b/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner.csv @@ -0,0 +1,5 @@ +firstname,lastname,name,email +NOM FAMILLE,Prénom,,contact1@import.com +Que NOM,,,contact2@import.com +,Que Prénom,,contact3@import.com +,,TEST NOM dans NAME,contact4@import.com diff --git a/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner_incorrect.csv b/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner_incorrect.csv new file mode 100644 index 0000000..6faa4c1 --- /dev/null +++ b/fermente_custom_import_partner_firstname/tests/templates/res.partner/partner_incorrect.csv @@ -0,0 +1,2 @@ +firstname,lastname,name,email +NOM FAMILLE,Prénom,ET NOM,contact1@import.com diff --git a/fermente_custom_import_partner_firstname/tests/test_module.py b/fermente_custom_import_partner_firstname/tests/test_module.py new file mode 100644 index 0000000..a8bddba --- /dev/null +++ b/fermente_custom_import_partner_firstname/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_base.tests.test_module_partner import ( + TestModulePartner, +) + + +@tagged("post_install", "-at_install") +class TestModulePartnerFirstname(TestModulePartner): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_01_import_partner_first_name(self): + partners, messages = self._test_import_file( + "fermente_custom_import_partner_firstname", + "res.partner", + "partner.csv", + ) + self.assertFalse(messages) + self.assertEqual(len(partners), 4) + + partner_1 = partners.filtered(lambda x: x.email == "contact1@import.com") + partner_2 = partners.filtered(lambda x: x.email == "contact2@import.com") + partner_3 = partners.filtered(lambda x: x.email == "contact3@import.com") + partner_4 = partners.filtered(lambda x: x.email == "contact4@import.com") + + self.assertEqual(partner_1.company_type, "person") + self.assertEqual(partner_2.company_type, "person") + self.assertEqual(partner_3.company_type, "person") + self.assertEqual(partner_4.company_type, "company") + + def test_02_import_contact_individual_and_company(self): + partners, messages = self._test_import_file( + "fermente_custom_import_partner_firstname", + "res.partner", + "partner_incorrect.csv", + ) + self.assertEqual(len(messages), 1) + self.assertEqual(messages[0].get("type"), "error") diff --git a/fermente_custom_import_product/models/custom_import_product_mixin.py b/fermente_custom_import_product/models/custom_import_product_mixin.py index e53dca3..a3f1cb3 100644 --- a/fermente_custom_import_product/models/custom_import_product_mixin.py +++ b/fermente_custom_import_product/models/custom_import_product_mixin.py @@ -16,11 +16,11 @@ def _custom_import_prevent_duplicate_fields(self): res += ["name", "barcode"] return res - # 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) self._custom_import_handle_uom_po_vals(old_vals, new_vals) + return def _custom_import_handle_supplierinfo_vals(self, old_vals, new_vals): supplier = self._custom_import_get_or_create( 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 index c413748..d7e1eb1 100644 --- a/fermente_custom_import_product_label/models/custom_import_product_mixin.py +++ b/fermente_custom_import_product_label/models/custom_import_product_mixin.py @@ -9,10 +9,10 @@ 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) + return def _custom_import_handle_product_label_vals(self, old_vals, new_vals): label_ids = [] diff --git a/fermente_custom_import_product_margin_classification/models/custom_import_product_mixin.py b/fermente_custom_import_product_margin_classification/models/custom_import_product_mixin.py index ad17ca6..24f3b6a 100644 --- a/fermente_custom_import_product_margin_classification/models/custom_import_product_mixin.py +++ b/fermente_custom_import_product_margin_classification/models/custom_import_product_mixin.py @@ -10,10 +10,10 @@ 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_margin_classification_vals(old_vals, new_vals) + return def _custom_import_handle_margin_classification_vals(self, old_vals, new_vals): profit_margin = ( diff --git a/setup/fermente_custom_import_partner_firstname/odoo/addons/fermente_custom_import_partner_firstname b/setup/fermente_custom_import_partner_firstname/odoo/addons/fermente_custom_import_partner_firstname new file mode 120000 index 0000000..5f851bf --- /dev/null +++ b/setup/fermente_custom_import_partner_firstname/odoo/addons/fermente_custom_import_partner_firstname @@ -0,0 +1 @@ +../../../../fermente_custom_import_partner_firstname \ No newline at end of file diff --git a/setup/fermente_custom_import_partner_firstname/setup.py b/setup/fermente_custom_import_partner_firstname/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/fermente_custom_import_partner_firstname/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)