From a49bd419a5b954e52d5adf49004c1dd92c5f4662 Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Fri, 15 Mar 2024 12:44:42 +0100 Subject: [PATCH] [ADD] partner_contact_email2 --- partner_contact_mail2/__init__.py | 5 +++ partner_contact_mail2/__manifest__.py | 39 +++++++++++++++++ partner_contact_mail2/models/__init__.py | 1 + partner_contact_mail2/models/res_partner.py | 47 +++++++++++++++++++++ partner_contact_mail2/views/res_partner.xml | 15 +++++++ 5 files changed, 107 insertions(+) create mode 100644 partner_contact_mail2/__init__.py create mode 100644 partner_contact_mail2/__manifest__.py create mode 100644 partner_contact_mail2/models/__init__.py create mode 100644 partner_contact_mail2/models/res_partner.py create mode 100644 partner_contact_mail2/views/res_partner.xml diff --git a/partner_contact_mail2/__init__.py b/partner_contact_mail2/__init__.py new file mode 100644 index 0000000..1760fa4 --- /dev/null +++ b/partner_contact_mail2/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# from . import controllers +# from . import models +# from . import wizards +# from .hooks import pre_init_hook, post_init_hook, uninstall_hook diff --git a/partner_contact_mail2/__manifest__.py b/partner_contact_mail2/__manifest__.py new file mode 100644 index 0000000..3ab6c04 --- /dev/null +++ b/partner_contact_mail2/__manifest__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": "Partner secondary email", + "version": "1.0.0", + "summary": "Partner secondary email", + "description": """ + Adds a secondary email field on res.partner model + """, + "author": "RemiFr82", + "contributors": "", + "maintainer": "RemiFr82", + "website": "https://remifr82.me", + "license": "LGPL-3", + "category": "", + # "price": 0, + # "currency": "EUR", + "application": False, + "installable": True, + "auto_install": False, + # "pre_init_hook": "", + # "post_init_hook": "", + # "uninstall_hook": "", + # "excludes": [], + # "external_dependencies": [], + "depends": [ + "base", + ], + "data": [ + # Views + "views/res_partner.xml", + ], + # "assets": [], + # "css": [], + # "images": [], + # "js": [], + # "test": [], + # "demo": [], +} diff --git a/partner_contact_mail2/models/__init__.py b/partner_contact_mail2/models/__init__.py new file mode 100644 index 0000000..46595e9 --- /dev/null +++ b/partner_contact_mail2/models/__init__.py @@ -0,0 +1 @@ +# from . import model \ No newline at end of file diff --git a/partner_contact_mail2/models/res_partner.py b/partner_contact_mail2/models/res_partner.py new file mode 100644 index 0000000..a200bc4 --- /dev/null +++ b/partner_contact_mail2/models/res_partner.py @@ -0,0 +1,47 @@ +import logging +from odoo import models, fields, api, tools + +_logger = logging.getLogger(__name__) + + +class WizardTechnicalName(models.Model): + _name = "wizard.technical.name" + _description = "Wizard Display Name" + + email2 = fields.Char("Email 2") + email2_formatted = fields.Char( + "Formatted Email 2", + compute="_compute_email2_formatted", + help='Format email address "Name "', + ) + + @api.depends("name", "email2") + def _compute_email2_formatted(self): + """Compute formatted email for partner, using formataddr. Be defensive + in computation, notably + + * double format: if email already holds a formatted email like + 'Name' we should not use it as it to compute + email formatted like "Name <'Name' >"; + * multi emails: sometimes this field is used to hold several addresses + like email1@domain.com, email2@domain.com. We currently let this value + untouched, but remove any formatting from multi emails; + * invalid email: if something is wrong, keep it in email2_formatted as + this eases management and understanding of failures at mail.mail, + mail.notification and mailing.trace level; + * void email: email2_formatted is False, as we cannot do anything with + it; + """ + self.email2_formatted = False + for partner in self: + emails_normalized = tools.email_normalize_all(partner.email) + if emails_normalized: + # note: multi-email input leads to invalid email like "Name" + # but this is current behavior in Odoo 14+ and some servers allow it + partner.email2_formatted = tools.formataddr( + (partner.name or "False", ",".join(emails_normalized)) + ) + elif partner.email: + partner.email2_formatted = tools.formataddr( + (partner.name or "False", partner.email) + ) diff --git a/partner_contact_mail2/views/res_partner.xml b/partner_contact_mail2/views/res_partner.xml new file mode 100644 index 0000000..91070cd --- /dev/null +++ b/partner_contact_mail2/views/res_partner.xml @@ -0,0 +1,15 @@ + + + + + res.partner.view.form.inherit + res.partner + + + + + + + + + \ No newline at end of file