[IMP] Added Mail Alis Impmentation for the Mail Group

bzr revid: jam@tinyerp.com-20120622090819-ps514pp2x3w5hm0p
This commit is contained in:
Jigar Amin - OpenERP 2012-06-22 14:38:19 +05:30
parent ae8f2af542
commit 541ec87069
4 changed files with 24 additions and 12 deletions

View File

@ -48,7 +48,9 @@ class mail_alias(osv.Model):
"existing record will cause the creation of a new record "
"of this model (e.g. a Project Task)",
# only allow selecting mail_thread models!
domain="[('field_ids', 'in', 'message_ids')]"),
#TODO kept doamin temporarily in comment, need to redefine domain
#domain="[('field_id', 'in', 'message_ids')]"
),
'alias_user_id': fields.many2one('res.users', 'Owner',
help="The owner of records created upon receiving emails on this alias. "
"If this field is kept empty the system will attempt to find the right owner "
@ -66,17 +68,20 @@ class mail_alias(osv.Model):
'alias_defaults': '{}',
'alias_user_id': lambda s,c,u,ctx: u
}
_sql_constraint = [
('mailbox_uniq', 'unique (alias_name)', 'Unfortunately this mail alias is already used, please choose a unique one')
_sql_constraints = [
('mailbox_uniq', 'UNIQUE(alias_name)', 'Unfortunately this mail alias is already used, please choose a unique one')
]
def create_unique_alias(self, cr, uid, values, context=None):
# TODO: call create() with `values` after checking that `alias_name`
# is unique. If not unique, append a sequential number after it until
# a unique one if found.
# E.g if create_unique_alias is called with {'alias_name': 'abc'}
# and 'abc', 'abc1', 'abc2' alias exist, replace alias_name with 'abc3'.
return
def create_unique_alias(self, cr, uid, values, sequence = 1 ,context=None):
config_parameter_pool = self.pool.get("ir.config_parameter")
domain = config_parameter_pool.get_param(cr, uid, "mail.catchall.domain", context=context)
prob_alias = "%s%s@%s"%(values['alias_name'], sequence, domain)
search_alias = self.search(cr, uid, [('alias_name', '=', prob_alias)])
if search_alias:
values = self.create_unique_alias(cr, uid, values, sequence+1, context)
else:
values.update({'alias_name': prob_alias})
return values

View File

@ -11,7 +11,7 @@
<field name="arch" type="xml">
<form string="Alias" version="7.0">
<sheet>
<group colspan="2" col="4">
<group colspan="4" col="4">
<field name="alias_name"/>
<field name="alias_model_id"/>
<field name="alias_user_id"/>

View File

@ -140,5 +140,9 @@ class mail_group(osv.osv):
def create(self, cr, uid, vals, context=None):
model_pool = self.pool.get('ir.model.data')
#TODO find the model id and pass and finish the all mail alias needs
alias_pool = self.pool.get('mail.alias')
model, res_id = model_pool.get_object_reference( cr, uid, "mail", "model_mail_group")
vals.update({'alias_name': "mailing-list",
'alias_model_id': res_id})
name = alias_pool.create_unique_alias(cr, uid, vals, context=context)
return super( mail_group, self).create(cr, uid, vals, context)

View File

@ -69,6 +69,9 @@
<field name="public" nolabel="1"/>
<label string="This group is visible by non members" colspan="2"/>
</group>
<group colspan="1" col="2">
<field name="alias_id" widget="selection" required="0" invisible="1"/>
</group>
</group>
<field name="message_ids" colspan="4" widget="ThreadView" nolabel="1"
options='{"thread_level": 1}'/>