diff --git a/mail_filter_adressee_by_contact/README.rst b/mail_filter_adressee_by_contact/README.rst new file mode 100644 index 0000000000..4975a63fa7 --- /dev/null +++ b/mail_filter_adressee_by_contact/README.rst @@ -0,0 +1,86 @@ +================================================== +Mail filter adressee by partner contacts and users +================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ef3e4593746f5854be3d1411efd707c0c8a7dbca426411dd1865e260f9e83735 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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/18.0/mail_filter_adressee_by_contact + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_filter_adressee_by_contact + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Filter adresses by partner contacts and users. It will be applied on +mails from the following models : - account.move - sale.order - +purchase.order - stock.picking + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Akretion + +Contributors +------------ + +Kévin Roche + +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-Kev-Roche| image:: https://github.com/Kev-Roche.png?size=40px + :target: https://github.com/Kev-Roche + :alt: Kev-Roche + +Current `maintainer `__: + +|maintainer-Kev-Roche| + +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_filter_adressee_by_contact/__init__.py b/mail_filter_adressee_by_contact/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_filter_adressee_by_contact/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_filter_adressee_by_contact/__manifest__.py b/mail_filter_adressee_by_contact/__manifest__.py new file mode 100644 index 0000000000..3e676d799e --- /dev/null +++ b/mail_filter_adressee_by_contact/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# @author Kévin Roche +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail filter adressee by partner contacts and users", + "summary": "Adresses filter by partner contacts and users", + "version": "18.0.1.1.0", + "category": "Social Network", + "website": "https://github.com/OCA/social", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainers": ["Kev-Roche"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mail", + "sale", + ], + "data": [ + "views/mail_compose_message_view.xml", + "views/mail_invoice_send_view.xml", + ], +} diff --git a/mail_filter_adressee_by_contact/i18n/es.po b/mail_filter_adressee_by_contact/i18n/es.po new file mode 100644 index 0000000000..6d61e99551 --- /dev/null +++ b/mail_filter_adressee_by_contact/i18n/es.po @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_filter_adressee_by_contact +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-26 19:33+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_account_invoice_send +msgid "Account Invoice Send" +msgstr "Cuenta de Envío de Factura" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__partner_ids +msgid "Additional Contacts" +msgstr "Contactos Adicionales" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__all +msgid "All" +msgstr "Todos/as" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__contacts +msgid "Contacts" +msgstr "Contactos" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__display_name +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_mail_compose_message +msgid "Email composition wizard" +msgstr "Asistente de redacción de correo electrónico" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__apply_filter +msgid "Filtering relevant adressees" +msgstr "Filtrar los destinatarios pertinentes" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__id +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__id +msgid "ID" +msgstr "ID" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send____last_update +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__users +msgid "Users" +msgstr "Usuarios" diff --git a/mail_filter_adressee_by_contact/i18n/fr.po b/mail_filter_adressee_by_contact/i18n/fr.po new file mode 100644 index 0000000000..608944313f --- /dev/null +++ b/mail_filter_adressee_by_contact/i18n/fr.po @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_filter_adressee_by_contact +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-07-04 15:05+0000\n" +"Last-Translator: Kévin Roche \n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_account_invoice_send +msgid "Account Invoice Send" +msgstr "Facture envoyée" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__partner_ids +msgid "Additional Contacts" +msgstr "Contacts supplémentaires" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__all +msgid "All" +msgstr "Tous" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__contacts +msgid "Contacts" +msgstr "Contacts" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__display_name +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_mail_compose_message +msgid "Email composition wizard" +msgstr "Assistant de composition de courriel" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__apply_filter +msgid "Filtering relevant adressees" +msgstr "Filtrage des destinataires" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__id +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__id +msgid "ID" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send____last_update +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__users +msgid "Users" +msgstr "Utilisateurs" diff --git a/mail_filter_adressee_by_contact/i18n/it.po b/mail_filter_adressee_by_contact/i18n/it.po new file mode 100644 index 0000000000..9cfecdeedb --- /dev/null +++ b/mail_filter_adressee_by_contact/i18n/it.po @@ -0,0 +1,72 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_filter_adressee_by_contact +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_account_invoice_send +msgid "Account Invoice Send" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__partner_ids +msgid "Additional Contacts" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__all +msgid "All" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__contacts +msgid "Contacts" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__display_name +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_mail_compose_message +msgid "Email composition wizard" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__apply_filter +msgid "Filtering relevant adressees" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__id +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__id +msgid "ID" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send____last_update +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__users +msgid "Users" +msgstr "" diff --git a/mail_filter_adressee_by_contact/i18n/mail_filter_adressee_by_contact.pot b/mail_filter_adressee_by_contact/i18n/mail_filter_adressee_by_contact.pot new file mode 100644 index 0000000000..b7b457c974 --- /dev/null +++ b/mail_filter_adressee_by_contact/i18n/mail_filter_adressee_by_contact.pot @@ -0,0 +1,71 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_filter_adressee_by_contact +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\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_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_account_invoice_send +msgid "Account Invoice Send" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__partner_ids +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__partner_ids +msgid "Additional Contacts" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__all +msgid "All" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__contacts +msgid "Contacts" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__display_name +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model,name:mail_filter_adressee_by_contact.model_mail_compose_message +msgid "Email composition wizard" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_tour_upload_bill__apply_filter +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__apply_filter +msgid "Filtering relevant adressees" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send__id +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message__id +msgid "ID" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_account_invoice_send____last_update +#: model:ir.model.fields,field_description:mail_filter_adressee_by_contact.field_mail_compose_message____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_filter_adressee_by_contact +#: model:ir.model.fields.selection,name:mail_filter_adressee_by_contact.selection__mail_compose_message__apply_filter__users +msgid "Users" +msgstr "" diff --git a/mail_filter_adressee_by_contact/models/__init__.py b/mail_filter_adressee_by_contact/models/__init__.py new file mode 100644 index 0000000000..37b1569fcc --- /dev/null +++ b/mail_filter_adressee_by_contact/models/__init__.py @@ -0,0 +1,3 @@ +from . import mail_filter_addressee_mixin +from . import mail_compose_message +from . import account_invoice_send diff --git a/mail_filter_adressee_by_contact/models/account_invoice_send.py b/mail_filter_adressee_by_contact/models/account_invoice_send.py new file mode 100644 index 0000000000..b77f236a90 --- /dev/null +++ b/mail_filter_adressee_by_contact/models/account_invoice_send.py @@ -0,0 +1,12 @@ +# Copyright (C) 2022 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountInvoiceSend(models.TransientModel): + _name = "account.move.send.wizard" + _inherit = ["account.move.send.wizard", "mail.filter.addressee.mixin"] + + _partner_ids_field = "mail_partner_ids" diff --git a/mail_filter_adressee_by_contact/models/mail_compose_message.py b/mail_filter_adressee_by_contact/models/mail_compose_message.py new file mode 100644 index 0000000000..4ffff67eb5 --- /dev/null +++ b/mail_filter_adressee_by_contact/models/mail_compose_message.py @@ -0,0 +1,35 @@ +# Copyright (C) 2021 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MailComposer(models.TransientModel): + _name = "mail.compose.message" + _inherit = ["mail.compose.message", "mail.filter.addressee.mixin"] + + def _get_domain_for_sale_order(self, records): + return [ + "|", + "|", + "|", + ("id", "child_of", records.partner_id.ids), + ("id", "child_of", records.partner_invoice_id.ids), + ("id", "child_of", records.partner_shipping_id.ids), + ("id", "in", records.message_partner_ids.ids), + ] + + def _get_domain_for_purchase_order(self, records): + return [ + "|", + ("id", "child_of", records.partner_id.ids), + ("id", "in", records.message_partner_ids.ids), + ] + + def _get_domain_for_stock_picking(self, records): + return [ + "|", + ("id", "child_of", records.partner_id.ids), + ("id", "in", records.message_partner_ids.ids), + ] diff --git a/mail_filter_adressee_by_contact/models/mail_filter_addressee_mixin.py b/mail_filter_adressee_by_contact/models/mail_filter_addressee_mixin.py new file mode 100644 index 0000000000..49506b4df1 --- /dev/null +++ b/mail_filter_adressee_by_contact/models/mail_filter_addressee_mixin.py @@ -0,0 +1,55 @@ +# Copyright (C) 2026 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.osv import expression + + +class MailFilterAddresseeMixin(models.AbstractModel): + _name = "mail.filter.addressee.mixin" + _description = "Mixin to filter mail addressees by contact type" + + # Name of the Many2many partner field targeted by the domain. + # Override in concrete models when the field is not 'partner_ids' + # (e.g. 'mail_partner_ids' on account.move.send.wizard). + _partner_ids_field = "partner_ids" + + apply_filter = fields.Selection( + [ + ("contacts", "Contacts"), + ("users", "Users"), + ("all", "All"), + ], + string="Filtering relevant adressees", + default="contacts", + required=True, + ) + + partner_ids_domain = fields.Char( + compute="_compute_partner_ids_domain", + ) + + @api.depends("apply_filter") + def _compute_partner_ids_domain(self): + for record in self: + domain = [("email", "!=", False)] + model = self._context.get("active_model") + + if model and record.apply_filter == "contacts": + method_name = f"_get_domain_for_{model.replace('.', '_')}" + if hasattr(self, method_name): + records = self.env[model].browse(self._context.get("active_ids")) + partners = getattr(self, method_name)(records) + domain = expression.AND([domain, partners]) + + if record.apply_filter == "users": + domain = expression.AND([domain, [("user_ids", "!=", False)]]) + record.partner_ids_domain = str(domain) + + def _get_domain_for_account_move(self, records): + return [ + "|", + ("id", "child_of", records.partner_id.ids), + ("id", "in", records.message_partner_ids.ids), + ] diff --git a/mail_filter_adressee_by_contact/pyproject.toml b/mail_filter_adressee_by_contact/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mail_filter_adressee_by_contact/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_filter_adressee_by_contact/readme/CONTRIBUTORS.md b/mail_filter_adressee_by_contact/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..9a6faca7a6 --- /dev/null +++ b/mail_filter_adressee_by_contact/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +Kévin Roche \<\> diff --git a/mail_filter_adressee_by_contact/readme/DESCRIPTION.md b/mail_filter_adressee_by_contact/readme/DESCRIPTION.md new file mode 100644 index 0000000000..4419fefb93 --- /dev/null +++ b/mail_filter_adressee_by_contact/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +Filter adresses by partner contacts and users. It will be applied on +mails from the following models : - account.move - sale.order - +purchase.order - stock.picking diff --git a/mail_filter_adressee_by_contact/static/description/icon.png b/mail_filter_adressee_by_contact/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/mail_filter_adressee_by_contact/static/description/icon.png differ diff --git a/mail_filter_adressee_by_contact/static/description/index.html b/mail_filter_adressee_by_contact/static/description/index.html new file mode 100644 index 0000000000..3f75626d2a --- /dev/null +++ b/mail_filter_adressee_by_contact/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Mail filter adressee by partner contacts and users + + + +
+

Mail filter adressee by partner contacts and users

+ + +

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

+

Filter adresses by partner contacts and users. It will be applied on +mails from the following models : - account.move - sale.order - +purchase.order - stock.picking

+

Table of contents

+ +
+

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

+
    +
  • Akretion
  • +
+
+ +
+

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:

+

Kev-Roche

+

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_filter_adressee_by_contact/tests/__init__.py b/mail_filter_adressee_by_contact/tests/__init__.py new file mode 100644 index 0000000000..6c7eb923af --- /dev/null +++ b/mail_filter_adressee_by_contact/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_filter_adressee_by_contact diff --git a/mail_filter_adressee_by_contact/tests/test_mail_filter_adressee_by_contact.py b/mail_filter_adressee_by_contact/tests/test_mail_filter_adressee_by_contact.py new file mode 100644 index 0000000000..bed3c8bb86 --- /dev/null +++ b/mail_filter_adressee_by_contact/tests/test_mail_filter_adressee_by_contact.py @@ -0,0 +1,132 @@ +# Copyright (C) 2026 Akretion (). +# @author Kévin Roche +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import ast + +from odoo.tests.common import TransactionCase + + +class TestMailFilterAdresseeByContact(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.partner_main = cls.env["res.partner"].create( + {"name": "Principal Customer", "email": "client@example.com"} + ) + cls.partner_shipping = cls.env["res.partner"].create( + { + "name": "delivery Adress", + "type": "delivery", + "parent_id": cls.partner_main.id, + "email": "delivery@example.com", + } + ) + cls.partner_invoice = cls.env["res.partner"].create( + { + "name": "Invoice Adress", + "type": "invoice", + "parent_id": cls.partner_main.id, + "email": "invoice@example.com", + } + ) + cls.partner_follower = cls.env["res.partner"].create( + {"name": "follower", "email": "follower@example.com"} + ) + cls.partner_private = cls.env["res.partner"].create({"name": "no email"}) + cls.partner_user = cls.env.ref("base.partner_admin") + + cls.sale_order = cls.env["sale.order"].create( + { + "partner_id": cls.partner_main.id, + "partner_invoice_id": cls.partner_invoice.id, + "partner_shipping_id": cls.partner_shipping.id, + } + ) + cls.sale_order.message_subscribe(partner_ids=cls.partner_follower.ids) + + cls.invoice = cls.env["account.move"].create( + { + "move_type": "out_invoice", + "partner_id": cls.partner_main.id, + "partner_shipping_id": cls.partner_shipping.id, + "line_ids": [ + (0, 0, {"name": "Test Line", "quantity": 1, "price_unit": 100}), + ], + } + ) + cls.invoice.message_subscribe(partner_ids=cls.partner_follower.ids) + + def _make_composer(self, active_model, active_ids, apply_filter="contacts"): + return ( + self.env["mail.compose.message"] + .with_context( + active_model=active_model, + active_ids=active_ids, + ) + .create({"apply_filter": apply_filter}) + ) + + def _make_send_wizard(self, active_ids, apply_filter="contacts"): + context = { + "active_model": "account.move", + "active_ids": active_ids, + } + return ( + self.env["account.move.send.wizard"] + .with_context(**context) + .create({"apply_filter": apply_filter}) + ) + + def _eval_domain(self, domain_str): + return ast.literal_eval(domain_str) + + def test_composer_users_filter(self): + composer = self._make_composer( + "sale.order", self.sale_order.ids, apply_filter="users" + ) + domain = self._eval_domain(composer.partner_ids_domain) + partners = self.env["res.partner"].search(domain) + self.assertIn(self.partner_user, partners) + self.assertNotIn(self.partner_follower, partners) + self.assertNotIn(self.partner_private, partners) + + def test_composer_all_filter(self): + composer = self._make_composer( + "sale.order", self.sale_order.ids, apply_filter="all" + ) + domain = self._eval_domain(composer.partner_ids_domain) + partners = self.env["res.partner"].search(domain) + self.assertIn(self.partner_main, partners) + self.assertIn(self.partner_follower, partners) + self.assertIn(self.partner_user, partners) + self.assertNotIn(self.partner_private, partners) + + def test_send_wizard_contacts_filter(self): + self.invoice.action_post() + wizard = self._make_send_wizard(self.invoice.ids) + domain = self._eval_domain(wizard.partner_ids_domain) + partners = self.env["res.partner"].search(domain) + self.assertIn(self.partner_main, partners) + self.assertIn(self.partner_shipping, partners) + self.assertIn(self.partner_follower, partners) + self.assertNotIn(self.partner_private, partners) + + def test_send_wizard_users_filter(self): + self.invoice.action_post() + wizard = self._make_send_wizard(self.invoice.ids, apply_filter="users") + domain = self._eval_domain(wizard.partner_ids_domain) + partners = self.env["res.partner"].search(domain) + self.assertIn(self.partner_user, partners) + self.assertNotIn(self.partner_follower, partners) + self.assertNotIn(self.partner_private, partners) + + def test_send_wizard_all_filter(self): + self.invoice.action_post() + wizard = self._make_send_wizard(self.invoice.ids, apply_filter="all") + domain = self._eval_domain(wizard.partner_ids_domain) + partners = self.env["res.partner"].search(domain) + self.assertIn(self.partner_main, partners) + self.assertIn(self.partner_user, partners) + self.assertNotIn(self.partner_private, partners) diff --git a/mail_filter_adressee_by_contact/views/mail_compose_message_view.xml b/mail_filter_adressee_by_contact/views/mail_compose_message_view.xml new file mode 100644 index 0000000000..ed8b6e9836 --- /dev/null +++ b/mail_filter_adressee_by_contact/views/mail_compose_message_view.xml @@ -0,0 +1,22 @@ + + + + mail.compose.message.form + mail.compose.message + + + +
+ +
+
+ + partner_ids_domain + +
+
+
diff --git a/mail_filter_adressee_by_contact/views/mail_invoice_send_view.xml b/mail_filter_adressee_by_contact/views/mail_invoice_send_view.xml new file mode 100644 index 0000000000..e465115c48 --- /dev/null +++ b/mail_filter_adressee_by_contact/views/mail_invoice_send_view.xml @@ -0,0 +1,22 @@ + + + + Send Invoice + account.move.send.wizard + + + +
+ +
+
+ + partner_ids_domain + +
+
+