diff --git a/CHANGELOG b/CHANGELOG index cc2152febf..cdde858205 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,4 @@ +* Add contact mechanism usage + Version 4.6.0 - 2017-10-30 -* Initial release \ No newline at end of file +* Initial release diff --git a/notification.py b/notification.py index 91a863dc23..f81b2ed129 100644 --- a/notification.py +++ b/notification.py @@ -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: diff --git a/view/email_form.xml b/view/email_form.xml index f0c214f952..d5bb9febfa 100644 --- a/view/email_form.xml +++ b/view/email_form.xml @@ -12,6 +12,8 @@ this repository contains the full copyright notices and license terms. -->