[IMP]: Improved code.

bzr revid: uco@tinyerp.com-20120227055653-ivwinivk912le3na
This commit is contained in:
Ujjvala Collins (OpenERP)
2012-02-27 11:26:53 +05:30
parent 2d88b48882
commit e3c42e0aff
2 changed files with 83 additions and 60 deletions
+53 -23
View File
@@ -22,6 +22,12 @@
from osv import fields, osv
import pooler
MODULE_LIST = [
'analytic_user_function', 'analytic_journal_billing_rate', 'import_sugarcrm',
'import_google', 'crm_caldav', 'wiki_sale_faq', 'base_contact',
'google_map', 'fetchmail_crm', 'plugin_thunderbird', 'plugin_outlook'
]
class sale_configuration(osv.osv_memory):
_name = 'sale.configuration'
_inherit = 'res.config'
@@ -33,22 +39,21 @@ class sale_configuration(osv.osv_memory):
'import_google' : fields.boolean("Import Contacts & Meetings from Google"),
'crm_caldav' : fields.boolean("Use caldav to synchronize Meetings"),
'wiki_sale_faq' : fields.boolean("Install a sales FAQ?"),
'crm_partner_assign' : fields.boolean("Manage a several address per customer"),
'base_contact' : fields.boolean("Manage a several address per customer"),
'google_map' : fields.boolean("Google maps on customer"),
'create_leads': fields.boolean("Create Leads from an Email Account"),
'server' : fields.char('Server Name', size=256, required=True),
'port' : fields.integer('Port', required=True),
'fetchmail_crm': fields.boolean("Create Leads from an Email Account"),
'server' : fields.char('Server Name', size=256),
'port' : fields.integer('Port'),
'type':fields.selection([
('pop', 'POP Server'),
('imap', 'IMAP Server'),
('local', 'Local Server'),
], 'Server Type', required=True),
], 'Server Type'),
'is_ssl': fields.boolean('SSL/TLS', help="Connections are encrypted with SSL/TLS through a dedicated port (default: IMAPS=993, POP=995)"),
'user' : fields.char('Username', size=256, required=True),
'password' : fields.char('Password', size=1024, required=True),
'user' : fields.char('Username', size=256),
'password' : fields.char('Password', size=1024),
'plugin_thunderbird': fields.boolean('Push your email from Thunderbird to an OpenERP document'),
'plugin_outlook': fields.boolean('Push your email from Outlook to an OpenERP document'),
}
def get_applied_groups(self, cr, uid, groups, context=None):
@@ -88,14 +93,13 @@ class sale_configuration(osv.osv_memory):
def default_get(self, cr, uid, fields_list, context=None):
result = super(sale_configuration, self).default_get(
cr, uid, fields_list, context=context)
module_list = ['analytic_user_function', 'analytic_journal_billing_rate', 'import_sugarcrm',
'import_google', 'crm_caldav', 'wiki_sale_faq', 'crm_partner_assign',
'google_map', 'plugin_thunderbird', 'plugin_outlook']
installed_modules = self.get_installed_modules(cr, uid, module_list, context=context)
installed_modules = self.get_installed_modules(cr, uid, MODULE_LIST, context=context)
result.update(installed_modules)
if 'fetchmail_crm' in installed_modules.keys():
for val in ir_values_obj.get(cr, uid, 'default', False, ['fetchmail.server']):
result.update({val[1]: val[2]})
group_list =['group_sale_pricelist_per_customer','group_sale_uom_per_product','group_sale_delivery_address',
'group_sale_disc_per_sale_order_line','group_sale_notes_subtotal']
@@ -119,26 +123,52 @@ class sale_configuration(osv.osv_memory):
values['port'] = port
return {'value': values}
def create(self, cr, uid, vals, context=None):
ids = super(sale_configuration, self).create(cr, uid, vals, context=context)
self.execute(cr, uid, [ids], vals, context=context)
return ids
def write(self, cr, uid, ids, vals, context=None):
self.execute(cr, uid, ids, context=context)
self.execute(cr, uid, ids, vals, context=context)
return super(sale_configuration, self).write(cr, uid, ids, vals, context=context)
def execute(self, cr, uid, ids, context=None):
def execute(self, cr, uid, ids, vals, context=None):
#TODO: TO BE IMPLEMENTED
module_obj = self.pool.get('ir.module.module')
wizard = self.read(cr, uid, ids)[0]
module_list = ['analytic_user_function', 'analytic_journal_billing_rate', 'import_sugarcrm',
'import_google', 'crm_caldav', 'wiki_sale_faq', 'crm_partner_assign',
'google_map', 'plugin_thunderbird', 'plugin_outlook']
for k, v in wizard.items():
if k in module_list and v == True:
model_obj = self.pool.get('ir.model')
fetchmail_obj = self.pool.get('fetchmail.server')
ir_values_obj = self.pool.get('ir.values')
for k, v in vals.items():
if k in MODULE_LIST and v == True:
installed = self.get_installed_modules(cr, uid, [k], context)
if not installed:
module_id = module_obj.search(cr, uid, [('name','=',k)])[0]
module_obj.state_update(cr, uid, [module_id], 'to install', ['uninstalled'], context)
cr.commit()
pooler.restart_pool(cr.dbname, update_module=True)[1]
if vals.get('fetchmail_crm'):
object_id = model_obj.search(cr, uid, [('model','=','crm.lead')])[0]
fetchmail_vals = {
'name': 'Incoming Leads',
'object_id': object_id,
'server': vals.get('server'),
'port': vals.get('port'),
'is_ssl': vals.get('is_ssl'),
'type': vals.get('type'),
'user': vals.get('user'),
'password': vals.get('password')
}
if not self.get_installed_modules(cr, uid, ['fetchmail_crm'], context):
fetchmail_obj.create(cr, uid, fetchmail_vals, context=context)
else:
fetchmail_ids = fetchmail_obj.search(cr, uid, [('name','=','Incoming Leads')], context=context)
fetchmail_obj.write(cr, uid, fetchmail_ids, fetchmail_vals, context=context)
ir_values_obj.set(cr, uid, 'default', False, 'server', ['fetchmail.server'], fetchmail_vals.get('server'))
ir_values_obj.set(cr, uid, 'default', False, 'port', ['fetchmail.server'], fetchmail_vals.get('port'))
ir_values_obj.set(cr, uid, 'default', False, 'is_ssl', ['fetchmail.server'], fetchmail_vals.get('is_ssl'))
ir_values_obj.set(cr, uid, 'default', False, 'type', ['fetchmail.server'], fetchmail_vals.get('type'))
ir_values_obj.set(cr, uid, 'default', False, 'user', ['fetchmail.server'], fetchmail_vals.get('user'))
ir_values_obj.set(cr, uid, 'default', False, 'password', ['fetchmail.server'], fetchmail_vals.get('password'))
sale_configuration()
@@ -8,7 +8,7 @@
<field name="arch" type="xml">
<form string="Sale Configuration">
<separator string="Contracts" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<group colspan="4" col="4">
<field name="analytic_user_function"/>
<newline/>
@@ -17,60 +17,53 @@
</group>
</group>
<separator string="Emails" colspan="8"/>
<group col="8" colspan="4">
<field name="create_leads" colspan="4"/>
<group col="4" colspan="4" attrs="{'invisible': [('create_leads','=',False)]}">
<group col="8" colspan="4">
<field name="server"/>
<field name="type" nolabel="1" on_change="onchange_server_type(type, is_ssl)"/>
<field name="port"/>
<field name="is_ssl" on_change="onchange_server_type(type, is_ssl)"/>
</group>
<group col="4" colspan="4">
<group col="2" colspan="2">
<separator string="Plugins" colspan="2"/>
<field name="plugin_thunderbird" colspan="2"/>
<newline/>
<group col="4" colspan="2">
<field name="user"/>
<field name="password"/>
</group>
<field name="plugin_outlook" colspan="2"/>
</group>
<group col="4" colspan="4">
<field name="plugin_thunderbird"/>
<group col="2" colspan="2">
<separator string="Emails" colspan="4"/>
<field name="fetchmail_crm" colspan="2"/>
<newline/>
<field name="plugin_outlook"/>
<group col="4" colspan="4"
attrs="{'invisible': [('fetchmail_crm','=',False)]}">
<field name="server" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="type" nolabel="1" on_change="onchange_server_type(type, is_ssl)" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="port" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="is_ssl" on_change="onchange_server_type(type, is_ssl)"/>
<newline/>
<field name="user" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
<field name="password" attrs="{'required': [('fetchmail_crm','=',True)]}"/>
</group>
</group>
</group>
<separator string="Import and Synchronize data from an other application" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<group colspan="4" col="4">
<separator string="Import and Synchronize data from an other application" colspan="4"/>
<group colspan="2" col="2">
<field name="import_sugarcrm"/>
<newline/>
<field name="import_google"/>
<newline/>
</group>
<group colspan="4" col="4">
<newline/>
<group colspan="2" col="2">
<field name="crm_caldav"/>
<newline/>
</group>
</group>
<separator string="Documents and Wiki" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<newline/>
<group colspan="4" col="4">
<group colspan="2" col="2">
<separator string="Documents and Wiki" colspan="2"/>
<field name="wiki_sale_faq" />
<newline/>
</group>
</group>
<separator string="Customer Form" colspan="4"/>
<group colspan="4" col="8">
<group colspan="4" col="4">
<field name="crm_partner_assign"/>
<group colspan="2" col="2">
<separator string="Customer Form" colspan="2"/>
<field name="base_contact"/>
<newline/>
<field name="google_map"/>
<newline/>
</group>
</group>