[FIX] account_voucher: improvements
[odoo/odoo.git] / addons / email_template / email_template_account.py
index 1a1b6db..a5f5140 100644 (file)
@@ -80,22 +80,27 @@ class email_template_account(osv.osv):
         'name': fields.char('Description',
                         size=64, required=True,
                         readonly=True, select=True,
+                        help="The description is used as the Sender name along with the provided From Email, \
+unless it is already specified in the From Email, e.g: John Doe <john@doe.com>", 
                         states={'draft':[('readonly', False)]}),
+        'auto_delete': fields.boolean('Auto Delete', size=64, readonly=True, 
+                                      help="Permanently delete emails after sending", 
+                                      states={'draft':[('readonly', False)]}),
         'user':fields.many2one('res.users',
                         'Related User', required=True,
                         readonly=True, states={'draft':[('readonly', False)]}),
         'email_id': fields.char('From Email',
                         size=120, required=True,
                         readonly=True, states={'draft':[('readonly', False)]} ,
-                        help="eg: yourname@yourdomain.com "),
+                        help="eg: 'john@doe.com' or 'John Doe <john@doe.com>'"),
         'smtpserver': fields.char('Server',
                         size=120, required=True,
                         readonly=True, states={'draft':[('readonly', False)]},
-                        help="Enter name of outgoing server, eg:smtp.gmail.com "),
-        'smtpport': fields.integer('SMTP Port ',
+                        help="Enter name of outgoing server, eg: smtp.yourdomain.com"),
+        'smtpport': fields.integer('SMTP Port',
                         size=64, required=True,
                         readonly=True, states={'draft':[('readonly', False)]},
-                        help="Enter port number,eg:SMTP-587 "),
+                        help="Enter port number, eg: 25 or 587"),
         'smtpuname': fields.char('User Name',
                         size=120, required=False,
                         readonly=True, states={'draft':[('readonly', False)]},
@@ -133,7 +138,7 @@ class email_template_account(osv.osv):
                                   ('suspended', 'Suspended'),
                                   ('approved', 'Approved')
                                   ],
-                        'Status', required=True, readonly=True),
+                        'State', required=True, readonly=True),
     }
 
     _defaults = {
@@ -165,7 +170,7 @@ class email_template_account(osv.osv):
     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)
@@ -207,7 +212,7 @@ class email_template_account(osv.osv):
         #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:
@@ -248,10 +253,10 @@ class email_template_account(osv.osv):
         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")
@@ -262,12 +267,12 @@ class email_template_account(osv.osv):
         """
         #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
@@ -354,20 +359,20 @@ class email_template_account(osv.osv):
                             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 {'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):
         """
@@ -422,7 +427,7 @@ class email_template_account(osv.osv):
                       "Datetime Extraction failed.Date:%s \
                       \tError:%s") % (
                                     time_as_string,
-                                    e)
+                                    tools.ustr(e))
                       )
         return date_as_date