[IMP] improved code.
bzr revid: tpa@tinyerp.com-20120315061919-ek5efcwv7pgc9bvt
This commit is contained in:
parent
aca13da679
commit
836c1b70e5
|
@ -21,6 +21,7 @@
|
|||
|
||||
import crm_claim
|
||||
import report
|
||||
import res_config
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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()
|
|
@ -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:
|
|
@ -9,15 +9,15 @@
|
|||
<field name="inherit_id" ref="base.project_settings_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form/group[@name='Helpdesk and support']" position="inside">
|
||||
<field name="crm_claim"/>
|
||||
<group col="4" colspan="2" attrs="{'invisible': [('crm_claim','=',False)]}">
|
||||
<field name="claim_server" attrs="{'required': [('crm_claim','=',True)]}"/>
|
||||
<field name="claim_type" nolabel="1" on_change="onchange_server_type(claim_type, claim_is_ssl,'claim')" attrs="{'required': [('crm_claim','=',True)]}"/>
|
||||
<field name="claim_port" attrs="{'required': [('crm_claim','=',True)]}"/>
|
||||
<field name="project_claim"/>
|
||||
<group col="4" colspan="2" attrs="{'invisible': [('project_claim','=',False)]}">
|
||||
<field name="claim_server" attrs="{'required': [('project_claim','=',True)]}"/>
|
||||
<field name="claim_type" nolabel="1" on_change="onchange_server_type(claim_type, claim_is_ssl,'claim')" attrs="{'required': [('project_claim','=',True)]}"/>
|
||||
<field name="claim_port" attrs="{'required': [('project_claim','=',True)]}"/>
|
||||
<field name="claim_is_ssl" on_change="onchange_server_type(claim_type, claim_is_ssl,'claim')"/>
|
||||
<newline/>
|
||||
<field name="claim_user" attrs="{'required': [('crm_claim','=',True)]}"/>
|
||||
<field name="claim_password" password="True" attrs="{'required': [('crm_claim','=',True)]}"/>
|
||||
<field name="claim_user" attrs="{'required': [('project_claim','=',True)]}"/>
|
||||
<field name="claim_password" password="True" attrs="{'required': [('project_claim','=',True)]}"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -22,5 +22,6 @@
|
|||
|
||||
import project_issue
|
||||
import report
|
||||
import res_config
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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()
|
Loading…
Reference in New Issue