[IMP]: mail_gateway: Improvement for duplication checking and history view
bzr revid: rpa@openerp.co.in-20100205134943-7unz7lwpzyykppa8
This commit is contained in:
@@ -54,6 +54,22 @@ class mail_gateway_server(osv.osv):
|
||||
'server_type':lambda * a:'pop',
|
||||
'active':lambda * a:True,
|
||||
}
|
||||
|
||||
def check_duplicate(self, cr, uid, ids):
|
||||
vals = self.read(cr, uid, ids, ['name', 'login'])[0]
|
||||
cr.execute("select count(id) from mail_gateway_server \
|
||||
where name='%s' and login='%s'" % \
|
||||
(vals['name'], vals['login']))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
if res[0] > 1:
|
||||
return False
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(check_duplicate, 'Warning! Can\'t have duplicate server configuration!', ['name', 'login'])
|
||||
]
|
||||
|
||||
def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False):
|
||||
port = 0
|
||||
if server_type == 'pop':
|
||||
@@ -62,28 +78,6 @@ class mail_gateway_server(osv.osv):
|
||||
port = ssl and 993 or 143
|
||||
return {'value':{'port':port}}
|
||||
|
||||
def check_duplicate(self, cr, uid, vals, limit):
|
||||
cr.execute("select count(id) from mail_gateway_server \
|
||||
where name='%s' and server_type='%s' and login='%s'" % \
|
||||
(vals['name'], vals['server_type'], vals['login']))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
if res[0] > limit:
|
||||
raise osv.except_osv(_('Warning !'), _('Can\'t have duplicate server configuration!'))
|
||||
|
||||
def create(self, cr, uid, vals, context={}):
|
||||
self.check_duplicate(cr, uid, vals, 0)
|
||||
return super(mail_gateway_server, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if not vals:
|
||||
return
|
||||
res = super(mail_gateway_server, self).write(cr, uid, ids, vals, context)
|
||||
for id in ids:
|
||||
vals = self.read(cr, uid, id, ['name', 'server_type', 'login'], context=context)
|
||||
self.check_duplicate(cr, uid, vals, 1)
|
||||
return res
|
||||
|
||||
mail_gateway_server()
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="mail_gateway_history_form" model="ir.ui.view">
|
||||
<field name="name">mail.gateway.history.form</field>
|
||||
<field name="model">mail.gateway.history</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Gateway History">
|
||||
<field name="name"/>
|
||||
<field name="res_id"/>
|
||||
<separator string="Note" colspan="4"/>
|
||||
<field name="note" nolabel="1" colspan="4"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="mail_gateway_history_tree" model="ir.ui.view">
|
||||
<field name="name">mail.gateway.history.tree</field>
|
||||
<field name="model">mail.gateway.history</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Gateway History">
|
||||
<field name="name" select="1"/>
|
||||
<field name="res_id"/>
|
||||
<field name="gateway_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="mail_gateway_act" model="ir.actions.act_window">
|
||||
<field name="name">Gateway History</field>
|
||||
<field name="res_model">mail.gateway.history</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="mail_gateway_history_tree"/>
|
||||
</record>
|
||||
|
||||
<act_window context="{'gateway_id': active_id}"
|
||||
domain="[('gateway_id', '=', active_id)]"
|
||||
id="act_gateway_history" name="Email History"
|
||||
res_model="mail.gateway.history" src_model="mail.gateway" />
|
||||
|
||||
<record id="mail_gateway_form" model="ir.ui.view">
|
||||
<field name="name">mail.gateway.form</field>
|
||||
<field name="model">mail.gateway</field>
|
||||
@@ -12,18 +53,6 @@
|
||||
<field name="server_id" />
|
||||
<field name="reply_to"/>
|
||||
<field name="email_default" />
|
||||
<field name="mail_history" widget="one2many_list" nolabel="1" colspan="4">
|
||||
<tree string="Email History">
|
||||
<field name="name"/>
|
||||
<field name="res_id"/>
|
||||
</tree>
|
||||
<form string="Email History">
|
||||
<field name="name"/>
|
||||
<field name="res_id"/>
|
||||
<separator colspan="4" string="Notes"/>
|
||||
<field name="note" nolabel="1" colspan="4"/>
|
||||
</form>
|
||||
</field>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user