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] [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.