[IMP] Consstance write method for the wrting the unique and nautral mail alias
authorJigar Amin - OpenERP <jam@tinyerp.com>
Tue, 26 Jun 2012 12:29:01 +0000 (17:59 +0530)
committerJigar Amin - OpenERP <jam@tinyerp.com>
Tue, 26 Jun 2012 12:29:01 +0000 (17:59 +0530)
bzr revid: jam@tinyerp.com-20120626122901-bkq4smyhw3yop8nz

addons/mail/mail_alias.py

index 54adfa3..bdb52ba 100644 (file)
@@ -20,6 +20,7 @@
 ##############################################################################
 
 from openerp.osv import fields, osv
+from tools.translate import _
 
 class mail_alias(osv.Model):
     """A Mail Alias is a mapping of an email address with a given OpenERP Document
@@ -82,4 +83,22 @@ class mail_alias(osv.Model):
         else:
             values.update({'alias_name': prob_alias})
             return values
-        
+    def write(self, cr, uid, ids, vals, context=None):
+        config_parameter_pool = self.pool.get("ir.config_parameter")
+        #TODO: Do we need to check specail charactor like email address parsing
+        #     Like allowing . and _ only.
+        if 'alias_name' in vals.keys():
+            domain = config_parameter_pool.get_param(cr, uid, "mail.catchall.domain", context=context)
+            #check the new alias, If only alias then concat the domain
+            #if we have alias_name with random domain we will concat our domain.
+            if vals.get('alias_name').count("@") == 0:
+                print "0"
+                vals.update({'alias_name': "%s@%s"%(vals.get('alias_name'), domain)})
+            elif vals.get('alias_name').count("@") == 1:
+                print "1"
+                name =  "%s@%s"%(vals.get('alias_name').split("@")[0], domain)
+                vals.update({'alias_name': name})
+            else:
+                raise osv.except_osv(_("Warning !"), _("Invalid mail alias name.\n It should be e.g. 'alias@domain.com' or only alias name 'alias'."))
+        return super(mail_alias, self).write(cr, uid, ids, vals, context=context)
+