changeset e454ba88f94c in modules/party:default
details: https://hg.tryton.org/modules/party?cmd=changeset;node=e454ba88f94c
description:
Send client email via server
issue9449
review292001002
diffstat:
__init__.py | 3 +
ir.py | 72 ++++++++++++++++++++++++++++++++++++++++++++
ir.xml | 12 +++++++
tryton.cfg | 1 +
view/email_template_form.xml | 9 +++++
5 files changed, 97 insertions(+), 0 deletions(-)
diffs (134 lines):
diff -r 93ce72852367 -r e454ba88f94c __init__.py
--- a/__init__.py Wed Sep 09 23:35:15 2020 +0200
+++ b/__init__.py Thu Sep 17 17:18:02 2020 +0200
@@ -7,6 +7,7 @@
from . import address
from . import contact_mechanism
from . import configuration
+from . import ir
def register():
@@ -26,6 +27,8 @@
configuration.Configuration,
configuration.ConfigurationSequence,
configuration.ConfigurationLang,
+ ir.Email,
+ ir.EmailTemplate,
module='party', type_='model')
Pool.register(
party.CheckVIES,
diff -r 93ce72852367 -r e454ba88f94c ir.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ir.py Thu Sep 17 17:18:02 2020 +0200
@@ -0,0 +1,72 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.model import fields
+from trytond.pool import PoolMeta, Pool
+from trytond.tools import escape_wildcard
+from trytond.transaction import Transaction
+
+
+class Email(metaclass=PoolMeta):
+ __name__ = 'ir.email'
+
+ @classmethod
+ def _match(cls, name, email):
+ pool = Pool()
+ ContactMechanism = pool.get('party.contact_mechanism')
+ yield from super()._match(name, email)
+ domain = ['OR']
+ for field in ['name', 'party.name', 'value']:
+ for value in [name, email]:
+ if value and len(value) >= 3:
+ domain.append(
+ (field, 'ilike', '%' + escape_wildcard(value) + '%'))
+ for contact in ContactMechanism.search([
+ ('type', '=', 'email'),
+ ('value', '!=', ''),
+ domain,
+ ], order=[]):
+ yield contact.name or contact.party.name, contact.value
+
+
+class EmailTemplate(metaclass=PoolMeta):
+ __name__ = 'ir.email.template'
+
+ contact_mechanism = fields.Selection(
+ 'get_contact_mechanisms', "Contact Mechanism",
+ help="Define which email address to use "
+ "from the party's contact mechanisms.")
+
+ @classmethod
+ def get_contact_mechanisms(cls):
+ pool = Pool()
+ ContactMechanism = pool.get('party.contact_mechanism')
+ return ContactMechanism.usages()
+
+ def get(self, record):
+ with Transaction().set_context(usage=self.contact_mechanism):
+ return super().get(record)
+
+ @classmethod
+ def email_models(cls):
+ return super().email_models() + ['party.party']
+
+ @classmethod
+ def _get_address(cls, record):
+ pool = Pool()
+ Party = pool.get('party.party')
+ address = super()._get_address(record)
+ if isinstance(record, Party):
+ usage = Transaction().context.get('usage')
+ contact = record.contact_mechanism_get('email', usage=usage)
+ if contact and contact.email:
+ address = (contact.name or record.name, contact.email)
+ return address
+
+ @classmethod
+ def _get_language(cls, record):
+ pool = Pool()
+ Party = pool.get('party.party')
+ language = super()._get_language(record)
+ if isinstance(record, Party) and record.lang:
+ language = record.lang
+ return language
diff -r 93ce72852367 -r e454ba88f94c ir.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ir.xml Thu Sep 17 17:18:02 2020 +0200
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<tryton>
+ <data>
+ <record model="ir.ui.view" id="email_template_view_form">
+ <field name="model">ir.email.template</field>
+ <field name="inherit" ref="ir.email_template_view_form"/>
+ <field name="name">email_template_form</field>
+ </record>
+ </data>
+</tryton>
diff -r 93ce72852367 -r e454ba88f94c tryton.cfg
--- a/tryton.cfg Wed Sep 09 23:35:15 2020 +0200
+++ b/tryton.cfg Thu Sep 17 17:18:02 2020 +0200
@@ -10,4 +10,5 @@
address.xml
contact_mechanism.xml
configuration.xml
+ ir.xml
message.xml
diff -r 93ce72852367 -r e454ba88f94c view/email_template_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/email_template_form.xml Thu Sep 17 17:18:02 2020 +0200
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+ <xpath expr="//field[@name='recipients_hidden']" position="after">
+ <label name="contact_mechanism"/>
+ <field name="contact_mechanism" colspan="3"/>
+ </xpath>
+</data>