Browse Source

[ADD] partner_contact_email2

16.0
RemiFr82 9 months ago
parent
commit
a49bd419a5
  1. 5
      partner_contact_mail2/__init__.py
  2. 39
      partner_contact_mail2/__manifest__.py
  3. 1
      partner_contact_mail2/models/__init__.py
  4. 47
      partner_contact_mail2/models/res_partner.py
  5. 15
      partner_contact_mail2/views/res_partner.xml

5
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

39
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": [],
}

1
partner_contact_mail2/models/__init__.py

@ -0,0 +1 @@
# from . import model

47
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 <email@domain>"',
)
@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' <email@domain.com> we should not use it as it to compute
email formatted like "Name <'Name' <email@domain.com>>";
* 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" <email1, email2>
# 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)
)

15
partner_contact_mail2/views/res_partner.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_form_inherit_base" model="ir.ui.view">
<field name="name">res.partner.view.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="email" position="after">
<field name="email2" widget="email" context="{'gravatar_image': True}" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save