[FIX] email_template, mail: added constraint and fix return type for mako template...
authorRifakat Haradwala (Open ERP) <rha@tinyerp.com>
Thu, 14 Apr 2011 11:34:01 +0000 (17:04 +0530)
committerRifakat Haradwala (Open ERP) <rha@tinyerp.com>
Thu, 14 Apr 2011 11:34:01 +0000 (17:04 +0530)
bzr revid: rha@tinyerp.com-20110414113401-dwhhu7srusqh4yfj

addons/email_template/mako_template.py
addons/mail/email_message.py

index f73b462..509bcbc 100644 (file)
@@ -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""
index d39b92c..a7dabf9 100644 (file)
@@ -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.