[FIX] account_voucher: improvements
[odoo/odoo.git] / addons / email_template / email_template_account.py
index ec8d644..a5f5140 100644 (file)
@@ -170,7 +170,7 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
     def name_get(self, cr, uid, ids, context=None):
         return [(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)]
 
-    def _constraint_unique(self, cursor, user, ids):
+    def _constraint_unique(self, cursor, user, ids, context=None):
         """
         This makes sure that you dont give personal 
         users two accounts with same ID (Validated in sql constaints)
@@ -212,7 +212,7 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
         #Type cast ids to integer
         if type(ids) == list:
             ids = ids[0]
-        this_object = self.browse(cursor, user, ids, context)
+        this_object = self.browse(cursor, user, ids, context=context)
         if this_object:
             if this_object.smtpserver and this_object.smtpport: 
                 try:
@@ -253,10 +253,10 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
         except Exception, error:
             raise osv.except_osv(
                                  _("Out going connection test failed"),
-                                 _("Reason: %s") % error
+                                 _("Reason: %s") % tools.ustr(error)
                                  )
     
-    def do_approval(self, cr, uid, ids, context={}):
+    def do_approval(self, cr, uid, ids, context=None):
         #TODO: Check if user has rights
         self.write(cr, uid, ids, {'state':'approved'}, context=context)
 #        wf_service = netsvc.LocalService("workflow")
@@ -267,12 +267,12 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
         """
         #This function returns a SMTP server object
         logger = netsvc.Logger()
-        core_obj = self.browse(cursor, user, id, context)
+        core_obj = self.browse(cursor, user, id, context=context)
         if core_obj.smtpserver and core_obj.smtpport and core_obj.state == 'approved':
             try:
                 serv = self.get_outgoing_server(cursor, user, id, context)
             except Exception, error:
-                logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed on login. Probable Reason:Could not login to server\nError: %s") % (id, error))
+                logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed on login. Probable Reason:Could not login to server\nError: %s") % (id, tools.ustr(error)))
                 return False
             #Everything is complete, now return the connection
             return serv
@@ -359,20 +359,20 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
                             Encoders.encode_base64(part)
                             payload_part.attach(part)
                 except Exception, error:
-                    logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, error))
-                    return {'error_msg': "Server Send Error\nDescription: %s"%error}
+                    logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, tools.ustr(error)))
+                    return {'error_msg': _("Server Send Error\nDescription: %s")%error}
                 try:
                     serv.sendmail(payload_part['From'], addresses_l['all-recipients'], payload_part.as_string())
                 except Exception, error:
-                    logging.getLogger('email_template').error("Mail from Account %s failed. Probable Reason: Server Send Error\n Description: %s", id, error, exc_info=True)
-                    return {'error_msg': "Server Send Error\nDescription: %s"%error}
+                    logging.getLogger('email_template').error(_("Mail from Account %s failed. Probable Reason: Server Send Error\n Description: %s"), id, tools.ustr(error), exc_info=True)
+                    return {'error_msg': _("Server Send Error\nDescription: %s") % tools.ustr(error)}
                 #The mail sending is complete
                 serv.close()
                 logger.notifyChannel(_("Email Template"), netsvc.LOG_INFO, _("Mail from Account %s successfully Sent.") % (id))
                 return True
             else:
                 logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id)
-                return {'nodestroy':True,'error_msg':"Mail from Account %s failed. Probable Reason:Account not approved"% id}
+                return {'nodestroy':True,'error_msg': _("Mail from Account %s failed. Probable Reason:Account not approved")% id}
 
     def extracttime(self, time_as_string):
         """
@@ -427,7 +427,7 @@ unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
                       "Datetime Extraction failed.Date:%s \
                       \tError:%s") % (
                                     time_as_string,
-                                    e)
+                                    tools.ustr(e))
                       )
         return date_as_date