From 9e80ee72bdc3aab68a89eb3ba3473f1a70168069 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Fri, 5 Feb 2010 19:19:43 +0530 Subject: [PATCH] [IMP]: mail_gateway: Improvement for duplication checking and history view bzr revid: rpa@openerp.co.in-20100205134943-7unz7lwpzyykppa8 --- addons/mail_gateway/mail_gateway.py | 38 +++++++--------- addons/mail_gateway/mail_gateway_view.xml | 53 ++++++++++++++++++----- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py index a10605212d0..314168c4b03 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/mail_gateway/mail_gateway.py @@ -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() diff --git a/addons/mail_gateway/mail_gateway_view.xml b/addons/mail_gateway/mail_gateway_view.xml index 3640d778ab0..465eea92b44 100644 --- a/addons/mail_gateway/mail_gateway_view.xml +++ b/addons/mail_gateway/mail_gateway_view.xml @@ -1,6 +1,47 @@ + + mail.gateway.history.form + mail.gateway.history + form + +
+ + + + + + +
+ + + mail.gateway.history.tree + mail.gateway.history + tree + + + + + + + + + + + + Gateway History + mail.gateway.history + form + tree,form + + + + + mail.gateway.form mail.gateway @@ -12,18 +53,6 @@ - - - - - -
- - - - - -