Add contact mechanism usage

issue7093
review43931002
This commit is contained in:
Cédric Krier committed 2018-02-19 19:16:17 +01:00
1 parent 0fd9140181
commit 3d101183a8
3 files changed
+23 -4

No files matched your search

+3 -1
View File
@@ -1,2 +1,4 @@
* Add contact mechanism usage
Version 4.6.0 - 2017-10-30
* Initial release
* Initial release
+18 -3
View File
@@ -57,6 +57,10 @@ class Email(ModelSQL, ModelView):
depends=['model'],
help="The field that contains the hidden recipient(s).")
contact_mechanism = fields.Selection(
'get_contact_mechanisms', "Contact Mechanism",
help="Define which email to use from the party's contact mechanisms")
content = fields.Many2One(
'ir.action.report', "Content", required=True,
domain=[('template_extension', 'in', ['txt', 'html', 'xhtml'])],
@@ -86,6 +90,15 @@ class Email(ModelSQL, ModelView):
def search_rec_name(cls, name, clause):
return [('content',) + tuple(clause[1:])]
@classmethod
def get_contact_mechanisms(cls):
pool = Pool()
try:
ContactMechanism = pool.get('party.contact_mechanism')
except KeyError:
return [(None, "")]
return ContactMechanism.usages()
@fields.depends('content')
def on_change_with_model(self, name=None):
if self.content:
@@ -108,9 +121,11 @@ class Email(ModelSQL, ModelView):
WebUser = None
if isinstance(record, User) and record.email:
return _formataddr(record.rec_name, record.email)
elif Party and isinstance(record, Party) and record.email:
# TODO similar to address_get for contact mechanism
return _formataddr(record.rec_name, record.email)
elif Party and isinstance(record, Party):
email = Party.contact_mechanism_get(
'email', usage=self.contact_mechanism)
if email:
return _formataddr(record.rec_name, email)
elif WebUser and isinstance(record, WebUser):
name = None
if record.party:
+2
View File
@@ -12,6 +12,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="recipients_secondary"/>
<label name="recipients_hidden"/>
<field name="recipients_hidden"/>
<label name="contact_mechanism"/>
<field name="contact_mechanism"/>
<field name="attachments" colspan="2"/>
<field name="triggers" colspan="2"/>
</form>