-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] fermente_custom_import_partner_firstname
- Loading branch information
1 parent
0b0a4c7
commit 3eccf28
Showing
26 changed files
with
202 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import custom_import_mixin | ||
from . import custom_import_partner_mixin | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
fermente_custom_import_base/models/custom_import_partner_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_module | ||
from . import test_module_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import custom_import_partner_mixin |
41 changes: 41 additions & 0 deletions
41
fermente_custom_import_partner_firstname/models/custom_import_partner_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
1 change: 1 addition & 0 deletions
1
fermente_custom_import_partner_firstname/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Sylvain LE GAL <https://twitter.com/legalsylvain> |
6 changes: 6 additions & 0 deletions
6
fermente_custom_import_partner_firstname/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_module |
5 changes: 5 additions & 0 deletions
5
fermente_custom_import_partner_firstname/tests/templates/res.partner/partner.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 2 additions & 0 deletions
2
fermente_custom_import_partner_firstname/tests/templates/res.partner/partner_incorrect.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
firstname,lastname,name,email | ||
NOM FAMILLE,Prénom,ET NOM,contact1@import.com |
44 changes: 44 additions & 0 deletions
44
fermente_custom_import_partner_firstname/tests/test_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ente_custom_import_partner_firstname/odoo/addons/fermente_custom_import_partner_firstname
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../fermente_custom_import_partner_firstname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |