diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index b37118c3baa..409551585fa 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -402,6 +402,7 @@ class account_invoice(osv.osv): 'default_res_id': ids[0], 'default_use_template': True, 'default_template_id': template_id, + 'default_composition_mode': 'comment', }) return { 'view_type': 'form', diff --git a/addons/account/edi/invoice_action_data.xml b/addons/account/edi/invoice_action_data.xml index 53fa03a6902..d86ebca3537 100644 --- a/addons/account/edi/invoice_action_data.xml +++ b/addons/account/edi/invoice_action_data.xml @@ -40,7 +40,7 @@ Automated Invoice Notification Mail ${object.user_id.email or object.company_id.email or 'noreply@localhost'} ${object.company_id.name} Invoice (Ref ${object.number or 'n/a' }) - ${object.partner_id.email or ''} + ${object.partner_id.id} - + + @@ -77,6 +78,7 @@ + diff --git a/addons/email_template/tests/test_mail.py b/addons/email_template/tests/test_mail.py index 7af05f38b0e..9a7b71a4e42 100644 --- a/addons/email_template/tests/test_mail.py +++ b/addons/email_template/tests/test_mail.py @@ -63,11 +63,16 @@ class test_message_compose(test_mail.TestMailMockups): # Create template on mail.group, with attachments group_model_id = self.registry('ir.model').search(cr, uid, [('model', '=', 'mail.group')])[0] email_template = self.registry('email.template') - email_template_id = email_template.create(cr, uid, {'model_id': group_model_id, - 'name': 'Pigs Template', 'subject': '${object.name}', - 'body_html': '${object.description}', 'user_signature': True, + email_template_id = email_template.create(cr, uid, { + 'model_id': group_model_id, + 'name': 'Pigs Template', + 'subject': '${object.name}', + 'body_html': '${object.description}', + 'user_signature': True, 'attachment_ids': [(0, 0, _attachments[0]), (0, 0, _attachments[1])], - 'email_to': 'b@b.b c@c.c', 'email_cc': 'd@d.d'}) + 'email_to': 'b@b.b c@c.c', + 'email_cc': 'd@d.d' + }) # ---------------------------------------- # CASE1: comment and save as template @@ -76,9 +81,9 @@ class test_message_compose(test_mail.TestMailMockups): # 1. Comment on pigs compose_id = mail_compose.create(cr, uid, {'subject': 'Forget me subject', 'body': '

Dummy body

'}, - {'default_composition_mode': 'comment', 'default_model': 'mail.group', + {'default_composition_mode': 'comment', + 'default_model': 'mail.group', 'default_res_id': self.group_pigs_id, - 'default_template_id': email_template_id, 'active_ids': [self.group_pigs_id, self.group_bird_id]}) compose = mail_compose.browse(cr, uid, compose_id) @@ -97,8 +102,10 @@ class test_message_compose(test_mail.TestMailMockups): # 1. Comment on pigs compose_id = mail_compose.create(cr, uid, {'subject': 'Forget me subject', 'body': 'Dummy body'}, - {'default_composition_mode': 'comment', 'default_model': 'mail.group', + {'default_composition_mode': 'comment', + 'default_model': 'mail.group', 'default_res_id': self.group_pigs_id, + 'default_use_template': False, 'default_template_id': email_template_id, 'active_ids': [self.group_pigs_id, self.group_bird_id]}) compose = mail_compose.browse(cr, uid, compose_id) @@ -135,8 +142,10 @@ class test_message_compose(test_mail.TestMailMockups): # 1. Mass_mail on pigs and bird, with a default_partner_ids set to check he is correctly added compose_id = mail_compose.create(cr, uid, {'subject': 'Forget me subject', 'body': 'Dummy body'}, - {'default_composition_mode': 'mass_mail', 'default_model': 'mail.group', + {'default_composition_mode': 'mass_mail', + 'default_model': 'mail.group', 'default_res_id': self.group_pigs_id, + 'default_use_template': False, 'default_template_id': email_template_id, 'default_partner_ids': [p_a_id], 'active_ids': [self.group_pigs_id, self.group_bird_id]}) @@ -170,3 +179,26 @@ class test_message_compose(test_mail.TestMailMockups): partner_ids = self.res_partner.search(cr, uid, [('email', 'in', ['b@b.b', 'c@c.c', 'd@d.d'])]) self.assertEqual(set(message_pigs_pids), set(partner_ids), 'mail.message on pigs incorrect number of notified_partner_ids') self.assertEqual(set(message_bird_pids), set(partner_ids), 'mail.message on bird notified_partner_ids incorrect') + + # ---------------------------------------- + # CASE4: test newly introduced email_recipients field + # ---------------------------------------- + + # get already-created partners back + p_b_id = self.res_partner.search(cr, uid, [('email', '=', 'b@b.b')])[0] + p_c_id = self.res_partner.search(cr, uid, [('email', '=', 'c@c.c')])[0] + p_d_id = self.res_partner.search(cr, uid, [('email', '=', 'd@d.d')])[0] + # modify template: use email_recipients, use template and email address in email_to to test all features together + user_model_id = self.registry('ir.model').search(cr, uid, [('model', '=', 'res.users')])[0] + email_template.write(cr, uid, [email_template_id], { + 'model_id': user_model_id, + 'body_html': '${object.login}', + 'email_to': '${object.email} c@c', + 'email_recipients': '%i,%i' % (p_b_id, p_c_id), + 'email_cc': 'd@d', + }) + # patner by email + partner by id (no double) + send_to = [p_a_id, p_b_id, p_c_id, p_d_id] + # Generate messsage with default email and partner on template + mail_value = mail_compose.generate_email_for_composer(cr, uid, email_template_id, uid) + self.assertEqual(set(mail_value['partner_ids']), set(send_to), 'mail.message partner_ids list created by template is incorrect') diff --git a/addons/email_template/wizard/email_template_preview_view.xml b/addons/email_template/wizard/email_template_preview_view.xml index f91535a17a5..8dd4bc92ba7 100644 --- a/addons/email_template/wizard/email_template_preview_view.xml +++ b/addons/email_template/wizard/email_template_preview_view.xml @@ -17,6 +17,7 @@ + diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py index fe6f85da544..129c32722f5 100644 --- a/addons/email_template/wizard/mail_compose_message.py +++ b/addons/email_template/wizard/mail_compose_message.py @@ -52,8 +52,9 @@ class mail_compose_message(osv.TransientModel): context = {} result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context) result['template_id'] = context.get('default_template_id', context.get('mail.compose.template_id', False)) + # pre-render the template if any - if result.get('use_template'): + if result.get('use_template') and result.get('template_id'): onchange_res = self.onchange_use_template(cr, uid, [], result.get('use_template'), result.get('template_id'), result.get('composition_mode'), result.get('model'), result.get('res_id'), context=context) result.update(onchange_res['value']) @@ -65,6 +66,10 @@ class mail_compose_message(osv.TransientModel): 'template_id': fields.selection(_get_templates, 'Template', size=-1), } + _defaults = { + 'use_template': True, + } + def onchange_template_id(self, cr, uid, ids, use_template, template_id, composition_mode, model, res_id, context=None): """ - use_template not set: return default_get - use_template set in mass_mailing: we cannot render, so return the template values @@ -148,15 +153,23 @@ class mail_compose_message(osv.TransientModel): mail.compose.message, transform email_cc and email_to into partner_ids """ template_values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context) # filter template values - fields = ['body', 'body_html', 'subject', 'email_to', 'email_cc', 'attachments'] + fields = ['body', 'body_html', 'subject', 'email_to', 'email_recipients', 'email_cc', 'attachments'] values = dict((field, template_values[field]) for field in fields if template_values.get(field)) values['body'] = values.pop('body_html', '') # transform email_to, email_cc into partner_ids values['partner_ids'] = [] + mails = tools.email_split(values.pop('email_to', '') + ' ' + values.pop('email_cc', '')) for mail in mails: partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context) values['partner_ids'].append(partner_id) + email_recipients = values.pop('email_recipients', '') + if email_recipients: + for partner_id in email_recipients.split(','): + values['partner_ids'].append(int(partner_id)) + + values['partner_ids'] = list(set(values['partner_ids'])) + return values def render_message(self, cr, uid, wizard, res_id, context=None): diff --git a/addons/email_template/wizard/mail_compose_message_view.xml b/addons/email_template/wizard/mail_compose_message_view.xml index 05d0e8dffa1..0a530299d4a 100644 --- a/addons/email_template/wizard/mail_compose_message_view.xml +++ b/addons/email_template/wizard/mail_compose_message_view.xml @@ -8,23 +8,23 @@ - - - - - + + - -