From 836c1b70e5f405a2e12acebfda414bcc60633837 Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Thu, 15 Mar 2012 11:49:19 +0530 Subject: [PATCH] [IMP] improved code. bzr revid: tpa@tinyerp.com-20120315061919-ek5efcwv7pgc9bvt --- addons/crm_claim/__init__.py | 1 + addons/crm_claim/res_config.py | 37 ++++++ addons/fetchmail/res_config.py | 117 +++++++----------- .../fetchmail_crm_claim/res_config_view.xml | 14 +-- addons/project/res_config.py | 2 +- addons/project_issue/__init__.py | 1 + addons/project_issue/res_config.py | 37 ++++++ 7 files changed, 126 insertions(+), 83 deletions(-) create mode 100644 addons/crm_claim/res_config.py create mode 100644 addons/project_issue/res_config.py diff --git a/addons/crm_claim/__init__.py b/addons/crm_claim/__init__.py index 7395ea83fe5..2012c227adf 100644 --- a/addons/crm_claim/__init__.py +++ b/addons/crm_claim/__init__.py @@ -21,6 +21,7 @@ import crm_claim import report +import res_config # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm_claim/res_config.py b/addons/crm_claim/res_config.py new file mode 100644 index 00000000000..48f95d4b7ee --- /dev/null +++ b/addons/crm_claim/res_config.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields, osv + +class project_claim_mail_configuration(osv.osv_memory): + _inherit = 'project.config.settings' + + def get_default_claim_server(self, cr, uid, ids, context=None): + context = {'type':'issue'} + res = self.get_default_email_configurations(cr, uid, ids, context) + + return res + + def set_default_claim_server(self, cr, uid, ids, context=None): + context = {'type':'claim','obj':'crm.claim'} + res = self.set_email_configurations(cr, uid, ids, context) + +project_claim_mail_configuration() \ No newline at end of file diff --git a/addons/fetchmail/res_config.py b/addons/fetchmail/res_config.py index 6b0661afd03..226ac869092 100644 --- a/addons/fetchmail/res_config.py +++ b/addons/fetchmail/res_config.py @@ -28,87 +28,54 @@ class project_configuration(osv.osv_memory): _inherit = 'project.config.settings' def get_default_email_configurations(self, cr, uid, ids, context=None): - fetchmail_obj = self.pool.get('fetchmail.server') result = {} - issue_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Issues'),('state','!=','done')]) - if issue_ids: - result.update({'project_issue': True}) - if issue_ids: - issue_id = fetchmail_obj.browse(cr, uid, issue_ids[0], context=context) - result.update({'issue_server': issue_id.server}) - result.update({'issue_port': issue_id.port}) - result.update({'issue_is_ssl': issue_id.is_ssl}) - result.update({'issue_type': issue_id.type}) - result.update({'issue_user': issue_id.user}) - result.update({'issue_password': issue_id.password}) - - claim_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Claims'),('state','!=','done')]) - if claim_ids: - result.update({'crm_claim': True}) - if claim_ids: - claim_id = fetchmail_obj.browse(cr, uid, claim_ids[0], context=context) - result.update({'claim_server': claim_id.server}) - result.update({'claim_port': claim_id.port}) - result.update({'claim_is_ssl': claim_id.is_ssl}) - result.update({'claim_type': claim_id.type}) - result.update({'claim_user': claim_id.user}) - result.update({'claim_password': claim_id.password}) + if context and context.get('type'): + type = context.get('type') + fetchmail_obj = self.pool.get('fetchmail.server') + server_ids = fetchmail_obj.search(cr, uid, [('name','=',type),('state','!=','done')]) + if server_ids: + result.update({'project_'+type: True}) + server_id = fetchmail_obj.browse(cr, uid, server_ids[0]) + result.update({type+'_server': server_id.server}) + result.update({type+'_port': server_id.port}) + result.update({type+'_is_ssl': server_id.is_ssl}) + result.update({type+'_type': server_id.type}) + result.update({type+'_user': server_id.user}) + result.update({type+'_password': server_id.password}) return result def set_email_configurations(self, cr, uid, ids, context=None): - model_obj = self.pool.get('ir.model') - fetchmail_obj = self.pool.get('fetchmail.server') - ir_values_obj = self.pool.get('ir.values') - issue_id = model_obj.search(cr, uid, [('model','=','project.issue')]) - claim_id = model_obj.search(cr, uid, [('model','=','crm.claim')]) - vals = self.read(cr, uid, ids[0], [], context=context) - if vals.get('project_issue') and issue_id: - issue_vals = { - 'name': 'Incoming Issues', - 'object_id': issue_id[0], - 'server': vals.get('issue_server'), - 'port': vals.get('issue_port'), - 'is_ssl': vals.get('issue_is_ssl'), - 'type': vals.get('issue_type'), - 'user': vals.get('issue_user'), - 'password': vals.get('issue_password') - } - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Issues'),('state','!=','done')]) - if not server_ids: - server_ids = [fetchmail_obj.create(cr, uid, issue_vals, context=context)] + if context and context.get('type'): + model_obj = self.pool.get('ir.model') + fetchmail_obj = self.pool.get('fetchmail.server') + ir_values_obj = self.pool.get('ir.values') + model = context.get('obj') + type = context.get('type') + object_id = model_obj.search(cr, uid, [('model','=',model)]) + vals = self.read(cr, uid, ids[0], [], context=context) + if vals.get('project_'+type) and object_id: + server_vals = { + 'name': type, + 'object_id': object_id[0], + 'server': vals.get(type+'_server'), + 'port': vals.get(type+'_port'), + 'is_ssl': vals.get(type+'_is_ssl'), + 'type': vals.get(type+'_type'), + 'user': vals.get(type+'_user'), + 'password': vals.get(type+'_password') + } + server_ids = fetchmail_obj.search(cr, uid, [('name','=',type),('state','!=','done')]) + if not server_ids: + server_ids = [fetchmail_obj.create(cr, uid, server_vals, context=context)] + else: + server_ids = fetchmail_obj.search(cr, uid, [('name','=',type)], context=context) + fetchmail_obj.write(cr, uid, server_ids, server_vals, context=context) + fetchmail_obj.button_confirm_login(cr, uid, server_ids, context=None) + else: - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Issues')], context=context) - fetchmail_obj.write(cr, uid, server_ids, issue_vals, context=context) - fetchmail_obj.button_confirm_login(cr, uid, server_ids, context=None) - - else: - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Issues'),('state','=','done')]) - fetchmail_obj.set_draft(cr, uid, server_ids, context=None) - - if vals.get('crm_claim') and claim_id: - claim_vals = { - 'name': 'Incoming Claims', - 'object_id': claim_id[0], - 'server': vals.get('claim_server'), - 'port': vals.get('claim_port'), - 'is_ssl': vals.get('claim_is_ssl'), - 'type': vals.get('claim_type'), - 'user': vals.get('claim_user'), - 'password': vals.get('claim_password') - } - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Claims'),('state','!=','done')]) - if not server_ids: - server_ids = [fetchmail_obj.create(cr, uid, claim_vals, context=context)] - else: - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Claims')], context=context) - fetchmail_obj.write(cr, uid, server_ids, claim_vals, context=context) - fetchmail_obj.button_confirm_login(cr, uid, server_ids, context=None) - - else: - server_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Claims'),('state','=','done')]) - fetchmail_obj.set_draft(cr, uid, server_ids, context=None) - + server_ids = fetchmail_obj.search(cr, uid, [('name','=',type),('state','=','done')]) + fetchmail_obj.set_draft(cr, uid, server_ids, context=None) project_configuration() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/fetchmail_crm_claim/res_config_view.xml b/addons/fetchmail_crm_claim/res_config_view.xml index 08bd878d56a..9ec7c23cbed 100644 --- a/addons/fetchmail_crm_claim/res_config_view.xml +++ b/addons/fetchmail_crm_claim/res_config_view.xml @@ -9,15 +9,15 @@ - - - - - + + + + + - - + + diff --git a/addons/project/res_config.py b/addons/project/res_config.py index 5f281503457..1706acb5334 100644 --- a/addons/project/res_config.py +++ b/addons/project/res_config.py @@ -69,7 +69,7 @@ class project_configuration(osv.osv_memory): 'issue_is_ssl': fields.boolean('SSL/TLS', help="Connections are encrypted with SSL/TLS through a dedicated port (default: IMAPS=993, POP=995)"), 'issue_user' : fields.char('Username', size=256), 'issue_password' : fields.char('Password', size=1024), - 'crm_claim': fields.boolean("Create claims from an email account", + 'project_claim': fields.boolean("Create claims from an email account", help="""Allows you to configure your incoming mail server. And creates claims for your mails. """), 'claim_server' : fields.char('Server Name', size=256), diff --git a/addons/project_issue/__init__.py b/addons/project_issue/__init__.py index f519698a60c..b04f25914c7 100644 --- a/addons/project_issue/__init__.py +++ b/addons/project_issue/__init__.py @@ -22,5 +22,6 @@ import project_issue import report +import res_config # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project_issue/res_config.py b/addons/project_issue/res_config.py new file mode 100644 index 00000000000..2fe7cb0a387 --- /dev/null +++ b/addons/project_issue/res_config.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields, osv + +class project_issue_mail_configuration(osv.osv_memory): + _inherit = 'project.config.settings' + + def get_default_issue_server(self, cr, uid, ids, context=None): + context = {'type':'claim'} + res = self.get_default_email_configurations(cr, uid, ids, context) + return res + + def set_default_issue_server(self, cr, uid, ids, context=None): + context = {'type':'issue','obj':'project.issue'} + res = self.set_email_configurations(cr, uid, ids, context) + + +project_issue_mail_configuration() \ No newline at end of file