From e4307f2abadb1a73a9c64c77c8858bdd28667042 Mon Sep 17 00:00:00 2001 From: Matthias BARKAT Date: Tue, 5 Dec 2023 14:26:00 +0100 Subject: [PATCH] [ADD] mail_contact_type: Provides a method to use on mail templates to select contacts by their categories. --- mail_contact_type/README.rst | 100 ++++ mail_contact_type/__init__.py | 1 + mail_contact_type/__manifest__.py | 26 ++ mail_contact_type/i18n/fr.po | 115 +++++ mail_contact_type/i18n/mail_contact_type.pot | 114 +++++ mail_contact_type/models/__init__.py | 1 + mail_contact_type/models/mail_contact_type.py | 17 + mail_contact_type/models/res_partner.py | 34 ++ mail_contact_type/readme/DESCRIPTION.rst | 1 + mail_contact_type/readme/USAGE.rst | 12 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 435 ++++++++++++++++++ mail_contact_type/tests/__init__.py | 1 + .../tests/test_mail_contact_type.py | 139 ++++++ mail_contact_type/views/mail_contact_type.xml | 28 ++ mail_contact_type/views/menu.xml | 25 + mail_contact_type/views/res_partner.xml | 42 ++ .../odoo/addons/mail_contact_type | 1 + setup/mail_contact_type/setup.py | 6 + 19 files changed, 1100 insertions(+) create mode 100644 mail_contact_type/README.rst create mode 100644 mail_contact_type/__init__.py create mode 100644 mail_contact_type/__manifest__.py create mode 100644 mail_contact_type/i18n/fr.po create mode 100644 mail_contact_type/i18n/mail_contact_type.pot create mode 100644 mail_contact_type/models/__init__.py create mode 100644 mail_contact_type/models/mail_contact_type.py create mode 100644 mail_contact_type/models/res_partner.py create mode 100644 mail_contact_type/readme/DESCRIPTION.rst create mode 100644 mail_contact_type/readme/USAGE.rst create mode 100644 mail_contact_type/security/ir.model.access.csv create mode 100644 mail_contact_type/static/description/index.html create mode 100644 mail_contact_type/tests/__init__.py create mode 100644 mail_contact_type/tests/test_mail_contact_type.py create mode 100644 mail_contact_type/views/mail_contact_type.xml create mode 100644 mail_contact_type/views/menu.xml create mode 100644 mail_contact_type/views/res_partner.xml create mode 120000 setup/mail_contact_type/odoo/addons/mail_contact_type create mode 100644 setup/mail_contact_type/setup.py diff --git a/mail_contact_type/README.rst b/mail_contact_type/README.rst new file mode 100644 index 0000000000..2a656ef26b --- /dev/null +++ b/mail_contact_type/README.rst @@ -0,0 +1,100 @@ +================= +Mail Contact Type +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3806166f869c62618c8b1436e7b69ba890ccb894bcda11bc958dd5ab1d308542 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/14.0/mail_contact_type + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_contact_type + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Provides a method to use on mail templates to select contacts by their categories. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In the **Contacts > Configuration > Mailing > Contact type** you can create mail contact type. + +A mail contact type is defined by a name that will be displayed in the backoffice +and a code that will be used to find contacts related to this type. + +Then, you will need to define the mailing types for contacts. To achieve this +there is a field called **Mail Contact Types** into the contact form view. + +Last, to select proper contacts from email template configuration, +you will set the **To (partner)** field using jinja template +like this (assuming `object` as a field `partner_id`): +`${object.partner_id.contact_by_types('your_code1','your_code2')}` + +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 +~~~~~~~ + +* Foodles + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-petrus-v| image:: https://github.com/petrus-v.png?size=40px + :target: https://github.com/petrus-v + :alt: petrus-v + +Current `maintainer `__: + +|maintainer-petrus-v| + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_contact_type/__init__.py b/mail_contact_type/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_contact_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_contact_type/__manifest__.py b/mail_contact_type/__manifest__.py new file mode 100644 index 0000000000..340b2fbc73 --- /dev/null +++ b/mail_contact_type/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2023 Foodles (https://www.foodles.com/) +# @author Pierre Verkest +# @author Matthias Barkat +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Mail Contact Type", + "summary": "Mail Contact Type", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Productivity/Discuss", + "website": "https://github.com/OCA/social", + "author": "Foodles, Odoo Community Association (OCA)", + "maintainers": ["petrus-v"], + "license": "AGPL-3", + "depends": [ + "contacts", + "mail", + ], + "data": [ + "security/ir.model.access.csv", + "views/mail_contact_type.xml", + "views/res_partner.xml", + "views/menu.xml", + ], + "installable": True, +} diff --git a/mail_contact_type/i18n/fr.po b/mail_contact_type/i18n/fr.po new file mode 100644 index 0000000000..0188263e88 --- /dev/null +++ b/mail_contact_type/i18n/fr.po @@ -0,0 +1,115 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_contact_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\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: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__code +msgid "Code" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model,name:mail_contact_type.model_res_partner +msgid "Contact" +msgstr "" + +#. module: mail_contact_type +#: model_terms:ir.ui.view,arch_db:mail_contact_type.view_mail_contact_type_form +msgid "Contact Type" +msgstr "Type de contact" + +#. module: mail_contact_type +#: model:ir.actions.act_window,name:mail_contact_type.action_mail_contact_type +#: model_terms:ir.ui.view,arch_db:mail_contact_type.view_mail_contact_type_tree +msgid "Contact Types" +msgstr "Types de contact" + +#. module: mail_contact_type +#: model:ir.ui.menu,name:mail_contact_type.menu_contact_type_list +msgid "Contact types" +msgstr "Types de contact" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__create_date +msgid "Created on" +msgstr "Créé le" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__display_name +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__id +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type____last_update +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__write_uid +msgid "Last Updated by" +msgstr "Dernière mise à jour par" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__write_date +msgid "Last Updated on" +msgstr "Derière mise à jour le" + +#. module: mail_contact_type +#: model:ir.model,name:mail_contact_type.model_mail_contact_type +msgid "Mail Contact Type" +msgstr "Type de contact par mail" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_fsm_location__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_fsm_person__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_res_users__mail_contact_type_ids +msgid "Mail Contact Types" +msgstr "Types de contact par mail" + +#. module: mail_contact_type +#: model:ir.model.fields,help:mail_contact_type.field_fsm_location__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_fsm_person__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_res_partner__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_res_users__mail_contact_type_ids +msgid "Used by email template to select contacts by mail contact type" +msgstr "Utilisé par le modèle de courriel pour sélectionner les contacts par type de contact par courriel" + + +#. module: mail_contact_type +#: model:ir.ui.menu,name:mail_contact_type.menu_contact_type +msgid "Mailing" +msgstr "Email" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__name +msgid "Name" +msgstr "Nom" + +#. module: mail_contact_type +#: model:ir.model.constraint,message:mail_contact_type.constraint_mail_contact_type_code_uniq +msgid "The code must be unique" +msgstr "Le code doit être unique" diff --git a/mail_contact_type/i18n/mail_contact_type.pot b/mail_contact_type/i18n/mail_contact_type.pot new file mode 100644 index 0000000000..fffd572d8d --- /dev/null +++ b/mail_contact_type/i18n/mail_contact_type.pot @@ -0,0 +1,114 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_contact_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\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: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__code +msgid "Code" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model,name:mail_contact_type.model_res_partner +msgid "Contact" +msgstr "" + +#. module: mail_contact_type +#: model_terms:ir.ui.view,arch_db:mail_contact_type.view_mail_contact_type_form +msgid "Contact Type" +msgstr "" + +#. module: mail_contact_type +#: model:ir.actions.act_window,name:mail_contact_type.action_mail_contact_type +#: model_terms:ir.ui.view,arch_db:mail_contact_type.view_mail_contact_type_tree +msgid "Contact Types" +msgstr "" + +#. module: mail_contact_type +#: model:ir.ui.menu,name:mail_contact_type.menu_contact_type_list +msgid "Contact types" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__create_uid +msgid "Created by" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__create_date +msgid "Created on" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__display_name +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__id +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type____last_update +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__write_date +msgid "Last Updated on" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model,name:mail_contact_type.model_mail_contact_type +msgid "Mail Contact Type" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_fsm_location__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_fsm_person__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_res_partner__mail_contact_type_ids +#: model:ir.model.fields,field_description:mail_contact_type.field_res_users__mail_contact_type_ids +msgid "Mail Contact Types" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,help:mail_contact_type.field_fsm_location__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_fsm_person__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_res_partner__mail_contact_type_ids +#: model:ir.model.fields,help:mail_contact_type.field_res_users__mail_contact_type_ids +msgid "Used by email template to select contacts by mail contact type" +msgstr "" + +#. module: mail_contact_type +#: model:ir.ui.menu,name:mail_contact_type.menu_contact_type +msgid "Mailing" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.fields,field_description:mail_contact_type.field_mail_contact_type__name +msgid "Name" +msgstr "" + +#. module: mail_contact_type +#: model:ir.model.constraint,message:mail_contact_type.constraint_mail_contact_type_code_uniq +msgid "The code must be unique" +msgstr "" diff --git a/mail_contact_type/models/__init__.py b/mail_contact_type/models/__init__.py new file mode 100644 index 0000000000..14c507a27a --- /dev/null +++ b/mail_contact_type/models/__init__.py @@ -0,0 +1 @@ +from . import mail_contact_type, res_partner diff --git a/mail_contact_type/models/mail_contact_type.py b/mail_contact_type/models/mail_contact_type.py new file mode 100644 index 0000000000..6cb42539a1 --- /dev/null +++ b/mail_contact_type/models/mail_contact_type.py @@ -0,0 +1,17 @@ +# Copyright 2023 Foodles (https://www.foodles.com/) +# @author Pierre Verkest +# @author Matthias Barkat +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class MailContactType(models.Model): + _name = "mail.contact.type" + _description = "Mail Contact Type" + + _sql_constraints = [ + ("code_uniq", "unique (code)", "The code must be unique"), + ] + + name = fields.Char(required=True, translate=True) + code = fields.Char(required=True) diff --git a/mail_contact_type/models/res_partner.py b/mail_contact_type/models/res_partner.py new file mode 100644 index 0000000000..ead277bd84 --- /dev/null +++ b/mail_contact_type/models/res_partner.py @@ -0,0 +1,34 @@ +# Copyright 2023 Foodles (https://www.foodles.com/) +# @author Pierre Verkest +# @author Matthias Barkat +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + mail_contact_type_ids = fields.Many2many( + "mail.contact.type", + string="Mail Contact Types", + help="Used by email template to select contacts by mail contact type", + ) + + def _find_contacts_by_mail_contact_types(self, codes): + return ( + self.commercial_partner_id.child_ids | self.commercial_partner_id + ).filtered( + lambda contact: any( + contact.mail_contact_type_ids.filtered( + lambda contact_type: contact_type.code in codes + ) + ) + ) + + def contact_by_types(self, *codes): + return ",".join( + [ + str(contact.id) + for contact in self._find_contacts_by_mail_contact_types(codes) + ] + ) diff --git a/mail_contact_type/readme/DESCRIPTION.rst b/mail_contact_type/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..a37a063bf3 --- /dev/null +++ b/mail_contact_type/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Provides a method to use on mail templates to select contacts by their categories. diff --git a/mail_contact_type/readme/USAGE.rst b/mail_contact_type/readme/USAGE.rst new file mode 100644 index 0000000000..de9534230f --- /dev/null +++ b/mail_contact_type/readme/USAGE.rst @@ -0,0 +1,12 @@ +In the **Contacts > Configuration > Mailing > Contact type** you can create mail contact type. + +A mail contact type is defined by a name that will be displayed in the backoffice +and a code that will be used to find contacts related to this type. + +Then, you will need to define the mailing types for contacts. To achieve this +there is a field called **Mail Contact Types** into the contact form view. + +Last, to select proper contacts from email template configuration, +you will set the **To (partner)** field using jinja template +like this (assuming `object` as a field `partner_id`): +`${object.partner_id.contact_by_types('your_code1','your_code2')}` diff --git a/mail_contact_type/security/ir.model.access.csv b/mail_contact_type/security/ir.model.access.csv new file mode 100644 index 0000000000..67992222c1 --- /dev/null +++ b/mail_contact_type/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_mail_contact_type,access_mail_contact_type,model_mail_contact_type,base.group_user,1,1,1,1 diff --git a/mail_contact_type/static/description/index.html b/mail_contact_type/static/description/index.html new file mode 100644 index 0000000000..4d2dae5eb0 --- /dev/null +++ b/mail_contact_type/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Mail Contact Type + + + +
+

Mail Contact Type

+ + +

Alpha License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

Provides a method to use on mail templates to select contacts by their categories.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+

In the Contacts > Configuration > Mailing > Contact type you can create mail contact type.

+

A mail contact type is defined by a name that will be displayed in the backoffice +and a code that will be used to find contacts related to this type.

+

Then, you will need to define the mailing types for contacts. To achieve this +there is a field called Mail Contact Types into the contact form view.

+

Last, to select proper contacts from email template configuration, +you will set the To (partner) field using jinja template +like this (assuming object as a field partner_id): +${object.partner_id.contact_by_types(‘your_code1’,’your_code2’)}

+
+
+

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

+
    +
  • Foodles
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

petrus-v

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_contact_type/tests/__init__.py b/mail_contact_type/tests/__init__.py new file mode 100644 index 0000000000..faad4fc39d --- /dev/null +++ b/mail_contact_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_contact_type diff --git a/mail_contact_type/tests/test_mail_contact_type.py b/mail_contact_type/tests/test_mail_contact_type.py new file mode 100644 index 0000000000..7dcfbb3ff2 --- /dev/null +++ b/mail_contact_type/tests/test_mail_contact_type.py @@ -0,0 +1,139 @@ +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# @author Matthias BARKAT +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + + +class TestMailContactType(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.mail_contact_type_invoice = cls.env["mail.contact.type"].create( + { + "name": "Invoice", + "code": "invoice", + } + ) + cls.mail_contact_type_sale = cls.env["mail.contact.type"].create( + { + "name": "Sale", + "code": "sale", + } + ) + cls.mail_contact_type_purchase = cls.env["mail.contact.type"].create( + { + "name": "Purchase", + "code": "purchase", + } + ) + cls.mail_contact_type_communication = cls.env["mail.contact.type"].create( + { + "name": "Communication", + "code": "communication", + } + ) + + # THE COMPANY (invoice) + # | + # --------------------------------------------------- + # | | | | + # | | | | + # partner1 partner2 partner3 partner4 + # [invoice] [sale] [purchase] [invoice,sale] + + cls.main_partner = cls.env["res.partner"].create( + { + "name": "The company", + "email": "contact@company.com", + "is_company": True, + "mail_contact_type_ids": [(6, 0, [cls.mail_contact_type_invoice.id])], + } + ) + cls.partner1 = cls.env["res.partner"].create( + { + "name": "partner1", + "email": "partner1@company.com", + "parent_id": cls.main_partner.id, + "mail_contact_type_ids": [(6, 0, [cls.mail_contact_type_invoice.id])], + } + ) + cls.partner2 = cls.env["res.partner"].create( + { + "name": "partner2", + "email": "partner2@company.com", + "parent_id": cls.main_partner.id, + "mail_contact_type_ids": [(6, 0, [cls.mail_contact_type_sale.id])], + } + ) + cls.partner3 = cls.env["res.partner"].create( + { + "name": "partner3", + "email": "partner3@company.com", + "parent_id": cls.main_partner.id, + "mail_contact_type_ids": [(6, 0, [cls.mail_contact_type_purchase.id])], + } + ) + cls.partner4 = cls.env["res.partner"].create( + { + "name": "partner4", + "email": "partner4@company.com", + "parent_id": cls.main_partner.id, + "mail_contact_type_ids": [ + ( + 6, + 0, + [ + cls.mail_contact_type_invoice.id, + cls.mail_contact_type_sale.id, + ], + ) + ], + } + ) + + def test_find_contacts_by_mail_contact_type(self): + self.assertEqual( + self.main_partner._find_contacts_by_mail_contact_types(["invoice"]), + self.partner1 | self.partner4 | self.main_partner, + ) + self.assertEqual( + self.main_partner._find_contacts_by_mail_contact_types(["sale"]), + self.partner2 | self.partner4, + ) + self.assertEqual( + self.main_partner._find_contacts_by_mail_contact_types(["purchase"]), + self.partner3, + ) + self.assertEqual( + self.main_partner._find_contacts_by_mail_contact_types(["communication"]), + self.env["res.partner"], + ) + self.assertEqual( + self.main_partner._find_contacts_by_mail_contact_types(["invoice", "sale"]), + self.partner1 | self.partner2 | self.partner4 | self.main_partner, + ) + + def test_contact_by_type(self): + self.assertEqual( + self.main_partner.contact_by_types("invoice"), + f"{self.partner1.id},{self.partner4.id},{self.main_partner.id}", + ) + self.assertEqual( + self.main_partner.contact_by_types("sale"), + f"{self.partner2.id},{self.partner4.id}", + ) + self.assertEqual( + self.main_partner.contact_by_types("purchase"), + f"{self.partner3.id}", + ) + self.assertEqual( + self.main_partner.contact_by_types("communication"), + "", + ) + self.assertEqual( + self.main_partner.contact_by_types("invoice", "sale"), + f"{self.partner1.id},{self.partner2.id},{self.partner4.id},{self.main_partner.id}", + ) diff --git a/mail_contact_type/views/mail_contact_type.xml b/mail_contact_type/views/mail_contact_type.xml new file mode 100644 index 0000000000..63c3e14f22 --- /dev/null +++ b/mail_contact_type/views/mail_contact_type.xml @@ -0,0 +1,28 @@ + + + + mail.contact.type.form + mail.contact.type + +
+ + + + + + +
+
+
+ + + mail.contact.type.tree + mail.contact.type + + + + + + + +
diff --git a/mail_contact_type/views/menu.xml b/mail_contact_type/views/menu.xml new file mode 100644 index 0000000000..e1af36b7bf --- /dev/null +++ b/mail_contact_type/views/menu.xml @@ -0,0 +1,25 @@ + + + + + Contact Types + mail.contact.type + tree,form + + + + + + + diff --git a/mail_contact_type/views/res_partner.xml b/mail_contact_type/views/res_partner.xml new file mode 100644 index 0000000000..c800348062 --- /dev/null +++ b/mail_contact_type/views/res_partner.xml @@ -0,0 +1,42 @@ + + + + res.partner.mail.contact.type.form + res.partner + + + + + + +
+ +
+
+ + + +
+
+ + + res.partner.mail.contact.type.tree + res.partner + + + + + + + +
diff --git a/setup/mail_contact_type/odoo/addons/mail_contact_type b/setup/mail_contact_type/odoo/addons/mail_contact_type new file mode 120000 index 0000000000..306f48a3be --- /dev/null +++ b/setup/mail_contact_type/odoo/addons/mail_contact_type @@ -0,0 +1 @@ +../../../../mail_contact_type \ No newline at end of file diff --git a/setup/mail_contact_type/setup.py b/setup/mail_contact_type/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_contact_type/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)