From ac8a9985e4a08750adf30bdeab1944feb65d7dee Mon Sep 17 00:00:00 2001 From: Jigar Amin - OpenERP Date: Wed, 4 Jul 2012 15:38:57 +0530 Subject: [PATCH] [USB/IMP] imporved the doc string and code fix bzr revid: jam@tinyerp.com-20120704100857-rrfdgmgr2hiynele --- addons/mail/mail_alias.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/mail/mail_alias.py b/addons/mail/mail_alias.py index 8fffbb4ee8b..06d24fca006 100644 --- a/addons/mail/mail_alias.py +++ b/addons/mail/mail_alias.py @@ -95,7 +95,7 @@ class mail_alias(osv.Model): dict(eval(record.alias_defaults)) except: return False - return True + return True _constraints = [ (_check_alias_defaults, "Default Values are in wrong format.\nIt must be in python dictionary format e.g.{'field_name': 'value' or {}}", ['alias_defaults']), @@ -114,6 +114,10 @@ class mail_alias(osv.Model): return res def _generate_alias(self, cr, uid, name, sequence=1 ,context=None): + """ + If alias is existing then this method will create a new unique alias name + by appending n sequence integer number. + """ new_name = "%s%s"%(name, sequence) search_alias = self.search(cr, uid, [('alias_name', '=', new_name)]) if search_alias: @@ -122,14 +126,21 @@ class mail_alias(osv.Model): return new_name def create_unique_alias(self, cr, uid, vals, context=None): + """ + Methods accepts the vals param in dict format and create new alias record + @vals : dict accept {alias_name: '', alias_model_id: '',...} + @return int: New alias_id + """ model_pool = self.pool.get('ir.model') - values = {} + values = {'alias_name': vals['alias_name']} + #Find for the mail alias exist or not if exit then get new mail address. if self.search(cr, uid, [('alias_name', '=', vals['alias_name'])]): values.update({'alias_name': self._generate_alias(cr, uid, vals['alias_name'], sequence=1, context=context)}) + alias_name = re.sub(r'[^a-zA-Z0-9:]', '_', values['alias_name']).lower() + values.update({'alias_name': alias_name}) + #Set the model fo rhte mail alias model_sids = model_pool.search(cr, uid, [('model', '=', vals['alias_model_id'])]) values.update({'alias_model_id': model_sids[0]}) - alias_name = re.sub(r'[^a-zA-Z0-9:]', '_', vals['alias_name']).lower() - values.update({'alias_name': values['alias_name']}) return self.create(cr, uid, values, context=context)