From db89a49fa0ea73f4cfe116fa79a4bea1e9bbb6e5 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 14 Apr 2011 10:25:03 +0530 Subject: [PATCH 1/9] [FIX] email_template: fix on_change_template bzr revid: rha@tinyerp.com-20110414045503-t1l81wx5n72ixa85 --- .../wizard/email_compose_message.py | 26 +++++++++---------- .../wizard/email_compose_message_view.xml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/email_template/wizard/email_compose_message.py b/addons/email_template/wizard/email_compose_message.py index 4086a4b1aee..8ec86f3f975 100644 --- a/addons/email_template/wizard/email_compose_message.py +++ b/addons/email_template/wizard/email_compose_message.py @@ -35,6 +35,7 @@ class email_compose_message(osv.osv_memory): template_pool = self.pool.get('email.template') if template_id: template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context) + def _get_template_value(field): if not template: return False @@ -42,10 +43,18 @@ class email_compose_message(osv.osv_memory): return getattr(template, field) else: # Simple Mail: Gets computed template values return template_pool.get_template_value(cr, uid, getattr(template, field), template.model, context.get('active_id'), context) + + body = _get_template_value('body') or False + if context.get('active_model') and context.get('active_id') and template.user_signature: + model_pool = self.pool.get(context['active_model']) + user = model_pool.browse(cr, uid, context['active_id'], context=context).user_id + signature = user and user.signature or '' + body = body + '\n' + signature + result.update({ 'template_id' : template.id, 'smtp_server_id' : template.smtp_server_id.id, - 'body' : _get_template_value('body') or False, + 'body' : body, 'subject' : _get_template_value('subject') or False, 'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [], 'res_id' : res_id or False, @@ -54,6 +63,7 @@ class email_compose_message(osv.osv_memory): 'email_bcc' : _get_template_value('email_bcc') or False, 'reply_to' : _get_template_value('reply_to') or False, 'model' : template.model or False, + 'auto_delete': template.auto_delete }) return result @@ -128,26 +138,16 @@ class email_compose_message(osv.osv_memory): 'template_id': fields.selection(_get_templates, 'Template'), } - def on_change_template(self, cr, uid, ids, model, template_id, context=None): + def on_change_template(self, cr, uid, ids, template_id, context=None): if context is None: context = {} - if context.get('mail') == 'reply': - return {'value':{}} vals = {} resource_id = context.get('active_id', False) if template_id and resource_id: - vals.update(self.get_template_data(cr, uid, resource_id, template_id, context)) + vals.update(self.get_template_data(cr, uid, resource_id, template_id, context=context)) else: vals.update({'attachment_ids' : []}) - email_temp_pool = self.pool.get('email.template') - template_data = email_temp_pool.browse(cr, uid, template_id, context=context) - vals.update({'auto_delete': template_data.auto_delete}) - if context.get('active_model') and context.get('active_id') and template_data.user_signature: - model_pool = self.pool.get(context['active_model']) - user = model_pool.browse(cr, uid, context['active_id'], context=context).user_id - signature = user and user.signature or '' - vals['body'] = vals['body'] + '\n' + signature return {'value': vals} email_compose_message() diff --git a/addons/email_template/wizard/email_compose_message_view.xml b/addons/email_template/wizard/email_compose_message_view.xml index 0a99d2af5e9..a2776662e0d 100644 --- a/addons/email_template/wizard/email_compose_message_view.xml +++ b/addons/email_template/wizard/email_compose_message_view.xml @@ -10,7 +10,7 @@ + on_change="on_change_template(template_id, context)"/> From c61bf2dcf477a4d6d2a5956f7c3b0dc131dfa3fa Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 14 Apr 2011 17:04:01 +0530 Subject: [PATCH 2/9] [FIX] email_template, mail: added constraint and fix return type for mako template in email_template bzr revid: rha@tinyerp.com-20110414113401-dwhhu7srusqh4yfj --- addons/email_template/mako_template.py | 4 +++- addons/mail/email_message.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/email_template/mako_template.py b/addons/email_template/mako_template.py index f73b462d7da..509bcbc66b3 100644 --- a/addons/email_template/mako_template.py +++ b/addons/email_template/mako_template.py @@ -47,7 +47,9 @@ def get_value(cr, uid, message=None, model=None, record_id=False, context=None): } templ = MakoTemplate(message, input_encoding='utf-8') reply = MakoTemplate(message).render_unicode(object=record, peobject=record, env=env, format_exceptions=True) - return reply or False + if reply == 'False': + reply = '' + return reply except Exception: logging.exception("can't render %r", message) return u"" diff --git a/addons/mail/email_message.py b/addons/mail/email_message.py index d39b92c8a8a..a7dabf905ef 100644 --- a/addons/mail/email_message.py +++ b/addons/mail/email_message.py @@ -94,6 +94,7 @@ class email_message_common(osv.osv_memory): _rec_name = 'subject' _sql_constraints = [] + email_message_common() class email_message(osv.osv): @@ -105,6 +106,19 @@ class email_message(osv.osv): _description = 'Email Message' _order = 'date desc' + def _check_email_recipients(self, cr, uid, ids, context=None): + ''' + checks email_to, email_cc, email_bcc + ''' + for message in self.browse(cr, uid, ids, context=context): + if not (message.email_to or message.email_cc or message.email_bcc): + return False + return True + + _constraints = [ + (_check_email_recipients, 'No recipients were specified. Please enter a recipient!', ['email_to', 'email_cc', 'email_bcc']), + ] + def open_document(self, cr, uid, ids, context=None): """ To Open Document @param self: The object pointer. From 0ad501441eb1cc7d3a1aac328bc65466a70c1b38 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 14 Apr 2011 17:19:18 +0530 Subject: [PATCH 3/9] [FIX] mail: fixed constraint and removed print statement bzr revid: rha@tinyerp.com-20110414114918-6yb1tzj6dr9u9ajz --- addons/mail/email_message.py | 2 +- addons/mail/wizard/email_compose_message.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/mail/email_message.py b/addons/mail/email_message.py index a7dabf905ef..b6c52d381f5 100644 --- a/addons/mail/email_message.py +++ b/addons/mail/email_message.py @@ -111,7 +111,7 @@ class email_message(osv.osv): checks email_to, email_cc, email_bcc ''' for message in self.browse(cr, uid, ids, context=context): - if not (message.email_to or message.email_cc or message.email_bcc): + if not (message.email_to or message.email_cc or message.email_bcc) and message.history: return False return True diff --git a/addons/mail/wizard/email_compose_message.py b/addons/mail/wizard/email_compose_message.py index fa7d8d74a96..8d5274aaa75 100644 --- a/addons/mail/wizard/email_compose_message.py +++ b/addons/mail/wizard/email_compose_message.py @@ -170,8 +170,6 @@ class email_compose_message(osv.osv_memory): else: message_id = mail.message_id - context.update({'mass_mail': True}) - print 'mail contx::', context # Mass mailing if context.get('mass_mail', False): if context['active_ids'] and context['active_model']: From 99bac0b9be878df5ccdb9c1118f4cb2245b35be7 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Thu, 14 Apr 2011 18:49:38 +0530 Subject: [PATCH 4/9] [REM] email_template: remove email_template_send wizard and IMP bzr revid: rha@tinyerp.com-20110414131938-5y133uyx5j7hl5v0 --- addons/email_template/__openerp__.py | 1 - addons/email_template/wizard/__init__.py | 1 - .../wizard/email_compose_message.py | 10 +- .../wizard/email_template_preview.py | 3 +- .../wizard/email_template_send_wizard.py | 166 ------------------ .../email_template_send_wizard_view.xml | 62 ------- 6 files changed, 6 insertions(+), 237 deletions(-) delete mode 100644 addons/email_template/wizard/email_template_send_wizard.py delete mode 100644 addons/email_template/wizard/email_template_send_wizard_view.xml diff --git a/addons/email_template/__openerp__.py b/addons/email_template/__openerp__.py index ef2d314e561..eab9f8bc148 100644 --- a/addons/email_template/__openerp__.py +++ b/addons/email_template/__openerp__.py @@ -42,7 +42,6 @@ for leads, the action will be added to the right side panel of the Lead form. "update_xml": [ 'wizard/email_template_preview_view.xml', 'email_template_view.xml', - 'wizard/email_template_send_wizard_view.xml', 'wizard/email_compose_message_view.xml', 'security/ir.model.access.csv' ], diff --git a/addons/email_template/wizard/__init__.py b/addons/email_template/wizard/__init__.py index 1bac2d4aaad..b0ad4313b4f 100644 --- a/addons/email_template/wizard/__init__.py +++ b/addons/email_template/wizard/__init__.py @@ -20,6 +20,5 @@ # ############################################################################## import email_template_preview -import email_template_send_wizard import email_compose_message diff --git a/addons/email_template/wizard/email_compose_message.py b/addons/email_template/wizard/email_compose_message.py index fc357c88a6e..82381c838e3 100644 --- a/addons/email_template/wizard/email_compose_message.py +++ b/addons/email_template/wizard/email_compose_message.py @@ -44,12 +44,10 @@ class email_compose_message(osv.osv_memory): else: return self.get_template_value(cr, uid, getattr(template, field), template.model, resource_id, context=context) - body = _get_template_value('body') or False - if context.get('active_model') and resource_id and template.user_signature: - model_pool = self.pool.get(context['active_model']) - user = model_pool.browse(cr, uid, resource_id, context=context).user_id - signature = user and user.signature or '' - body = body + '\n' + signature + body = _get_template_value('body') + if template.user_signature: + signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature + body += '\n' + signature result.update({ 'template_id' : template.id, diff --git a/addons/email_template/wizard/email_template_preview.py b/addons/email_template/wizard/email_template_preview.py index a1281831c4f..2538244ebea 100644 --- a/addons/email_template/wizard/email_template_preview.py +++ b/addons/email_template/wizard/email_template_preview.py @@ -46,8 +46,9 @@ class email_template_preview(osv.osv_memory): template = template_pool.browse(cr, uid, int(template_id), context=context) template_object = template.model_id model = self.pool.get(template_object.model) - record_ids = model.search(cr, uid, [], 0, 20, 'id', context=context) + record_ids = model.search(cr, uid, [], 0, 10, 'id', context=context) default_id = context.get('default_res_id') + if default_id and default_id not in record_ids: record_ids.insert(0, default_id) diff --git a/addons/email_template/wizard/email_template_send_wizard.py b/addons/email_template/wizard/email_template_send_wizard.py deleted file mode 100644 index b1c91401e55..00000000000 --- a/addons/email_template/wizard/email_template_send_wizard.py +++ /dev/null @@ -1,166 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2009 Sharoon Thomas -# Copyright (C) 2010-Today OpenERP SA () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# -############################################################################## - -from osv import osv, fields -import netsvc -from tools.translate import _ - -class email_template_send_wizard(osv.osv_memory): - _name = 'email_template.send.wizard' - _inherit = 'email.template' - _description = 'This is the wizard for sending mail' - - def default_get(self, cr, uid, fields, context=None): - if context is None: - context = {} - result = super(email_template_send_wizard, self).default_get(cr, uid, fields, context=context) - - template_pool = self.pool.get('email.template') - model_pool = self.pool.get('ir.model') - template_id=context.get('template_id', False) - template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context) - def _get_template_value(field): - if not template: - return False - if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change - return getattr(template, field) - else: # Simple Mail: Gets computed template values - return self.get_template_value(cr, uid, getattr(template, field), template.model, context.get('active_id'), context) - - if 'user_signature' in fields: - result['user_signature'] = template.user_signature - - if 'report_template' in fields: - result['report_template'] = template.report_template and template.report_template.id or False - - if 'template_id' in fields: - result['template_id'] = template.id - - if 'smtp_server_id' in fields: - result['smtp_server_id'] = template.smtp_server_id.id - - if 'attachment_ids' in fields: - result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] - - if 'requested' in fields: - result['requested'] = len(context.get('src_rec_ids','')) - - if 'state' in fields: - result['state'] = len(context.get('src_rec_ids','')) > 1 and 'multi' or 'single' - - if 'model_id' in fields: - result['model_id'] = model_pool.search(cr, uid, [('model','=',context.get('src_model'))],context=context)[0] - - if 'res_id' in fields: - result['res_id'] = context['active_id'] - - if 'email_to' in fields: - result['email_to'] = _get_template_value('email_to') - - if 'email_cc' in fields: - result['email_cc'] = _get_template_value('email_cc') - - if 'email_bcc' in fields: - result['email_bcc'] = _get_template_value('email_bcc') - - if 'subject' in fields: - result['subject'] = _get_template_value('subject') - - if 'body' in fields: - result['body'] = _get_template_value('description') - - #if 'body_html' in fields: - # result['body_html'] = _get_template_value('body_html') - - if 'reply_to' in fields: - result['reply_to'] = _get_template_value('reply_to') - - if 'report_name' in fields: - result['report_name'] = _get_template_value('report_name') - - return result - - _columns = { - 'requested':fields.integer('No of requested Mails',readonly=True), - 'generated':fields.integer('No of generated Mails',readonly=True), - 'full_success':fields.boolean('Complete Success',readonly=True), - 'attachment_ids': fields.many2many('ir.attachment','send_wizard_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'), - 'state':fields.selection([ - ('single','Simple Mail Wizard Step 1'), - ('multi','Multiple Mail Wizard Step 1'), - ('done','Wizard Complete') - ],'State',readonly=True), - } - - _defaults = { - } - - #def fields_get(self, cr, uid, fields=None, context=None, write_access=True): - # if context is None: - # context = {} - # result = super(email_template_send_wizard, self).fields_get(cr, uid, fields, context, write_access) - # if 'attachment_ids' in result and 'src_model' in context: - # result['attachment_ids']['domain'] = [('res_model','=',context['src_model']),('res_id','=',context['active_id'])] - # return result - - def send_mail(self, cr, uid, ids, context=None): - if context is None: - context = {} - mailid = self.save_to_mailbox(cr, uid, ids, context) - return {'type': 'ir.actions.act_window_close'} - - def get_generated(self, cr, uid, ids=None, context=None): - if ids is None: - ids = [] - if context is None: - context = {} - logger = netsvc.Logger() - if context.get('src_rec_ids'): - #Means there are multiple items selected for email. - mail_ids = self.save_to_mailbox(cr, uid, ids, context) - if mail_ids: - logger.notifyChannel("email-template", netsvc.LOG_INFO, _("Emails for multiple items saved in outbox.")) - self.write(cr, uid, ids, { - 'generated':len(mail_ids), - 'state':'done' - }, context) - else: - raise osv.except_osv(_("Email Template"),_("Email sending failed for one or more objects.")) - return True - - def save_to_mailbox(self, cr, uid, ids, context=None): - #def get_end_value(id, value): - # if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets value from the template - # return self.get_value(cr, uid, template, value, context, id) - # else: - # return value - - email_ids = [] - for template in self.browse(cr, uid, ids, context=context): - for record_id in context.get('src_rec_ids',[]): - email_id = self.generate_email(cr, uid, template.id, record_id, context) - email_ids.append(email_id) - return email_ids - -email_template_send_wizard() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/wizard/email_template_send_wizard_view.xml b/addons/email_template/wizard/email_template_send_wizard_view.xml deleted file mode 100644 index f82288575bb..00000000000 --- a/addons/email_template/wizard/email_template_send_wizard_view.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - email_template.send.wizard.form - email_template.send.wizard - form - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -