[IMP]: create wizard and changed in view. intregate attendee in import_base. create scheduler based on sugarcrm.

bzr revid: atp@tinyerp.com-20110519031237-kvwo64jcy9pncm78
This commit is contained in:
Atul Patel 2011-05-19 08:42:37 +05:30
parent 90e0fd284d
commit beff443988
5 changed files with 144 additions and 83 deletions

View File

@ -29,7 +29,7 @@
'website': 'http://www.openerp.com',
'depends': ['import_base', 'crm_claim', 'project', 'project_issue', 'project_timesheet', 'hr', 'document'],
'init_xml': [],
'update_xml': ["wizard/sugarcrm_login_view.xml",
'update_xml': [
"wizard/import_message_view.xml",
"import_sugarcrm_view.xml"],
'demo_xml': [],

View File

@ -60,19 +60,25 @@ class sugar_import(import_framework):
TABLE_EMAIL = 'Emails'
TABLE_DOCUMENT = 'DocumentRevisions'
TABLE_COMPAIGN = 'Campaigns'
TABLE_HISTORY_ATTACHMNET = 'history_attachment'
def initialize(self):
#login
PortType,sessionid = sugar.login(self.context.get('username',''), self.context.get('password',''), self.context.get('url',''))
if sessionid == '-1':
raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
self.context['port'] = PortType
self.context['session_id'] = sessionid
def get_data(self, table):
return sugar.search(self.context.get('port'), self.context.get('session_id'), table)
"""
Common import method
Common import method
"""
def get_category(self, val, model, name):
fields = ['name', 'object_id']
data = [name, model]
@ -130,14 +136,14 @@ class sugar_import(import_framework):
'datas_fname': 'datas_fname',
}
}
"""
import Emails
"""
def import_email(self, val):
model_obj = self.obj.pool.get('ir.model.data')
xml_id = self.xml_id_exist(val.get('parent_type'), val.get('parent_type'))
xml_id = self.xml_id_exist(val.get('parent_type'), val.get('parent_id'))
model_ids = model_obj.search(self.cr, self.uid, [('name', 'like', xml_id)])
if model_ids:
model = model_obj.browse(self.cr, self.uid, model_ids)[0]
@ -183,9 +189,9 @@ class sugar_import(import_framework):
fields = ['name', 'datas', 'datas_fname','res_id', 'res_model']
name = 'attachment_'+ (Filename or val.get('name'))
datas = [Filename or val.get('name'), File, Filename, val.get('res_id'),val.get('model',False)]
self.import_object(fields, datas, 'ir.attachment', 'history_attachment', name, [('res_id', '=', val.get('res_id'), ('model', '=', val.get('model')))])
attach_id = self.xml_id_exist('history_attachment', name)
return attach_id
attach_xml_id = self.import_object(fields, datas, 'ir.attachment', self.TABLE_HISTORY_ATTACHMNET, name, [('res_id', '=', val.get('res_id'), ('model', '=', val.get('model')))])
#attach_id = self.xml_id_exist(self.TABLE_HISTORY_ATTACHMNET, name)
return attach_xml_id
def import_history(self, val):
model_obj = self.obj.pool.get('ir.model.data')
@ -463,19 +469,27 @@ class sugar_import(import_framework):
#TODO
def get_attendee_id(self, cr, uid, module_name, module_id):
model_obj = self.obj.pool.get('ir.model.data')
user_obj = self.obj.pool.get('res.users')
address_obj = self.obj.pool.get('res.partner.address')
att_obj = self.obj.pool.get('calendar.attendee')
meeting_obj = self.obj.pool.get('crm.meeting')
user_dict = sugar.user_get_attendee_list(self.context.get('port'), self.context.get('session_id'), module_name, module_id)
#TODO there is more then just user in attendee list
#there is contact, partner, lead (but we don't import the link) and user
for user in user_dict:
continue
user_id = self.get_mapped_id(self.TABLE_USER, user.get('id'))
fields = ['user_id', 'email1']
data = [user_id, user.get('email1')]
self.import_object(fields, data, 'calendar.attendee', self.TABLE_ATTENDEE, user_id, [('user_id', '=', user_id)])
attendee_id = self.xml_id_exist(self.TABLE_ATTENDEE, user_id)
return attendee_id
attendee_dict = sugar.user_get_attendee_list(self.context.get('port'), self.context.get('session_id'), module_name, module_id)
contact_id = False
user_id = False
for attendee in attendee_dict:
model_ids = model_obj.search(self.cr, self.uid, [('name', 'like', attendee.get('id'))])
if model_ids:
model = model_obj.browse(self.cr, self.uid, model_ids)[0]
if model.model == 'res.users':
user_id = self.get_mapped_id(self.TABLE_USER, attendee.get('id', False))
elif model.model == 'res.partner.address':
contact_id = self.get_mapped_id(self.TABLE_CONTACT, attendee.get('id', False))
fields = ['user_id', 'email1', 'contact_id']
name = 'attendee_'+ attendee.get('id')
data = [user_id or False, attendee.get('email1'), contact_id]
attendee_xml_id = self.import_object(fields, data, 'calendar.attendee', self.TABLE_ATTENDEE, name, [('user_id', '=', user_id)])
#attendee_id = self.xml_id_exist(self.TABLE_ATTENDEE, name)
return attendee_xml_id
def get_alarm_id(self, dict_val, val):
alarm_dict = {
@ -490,14 +504,14 @@ class sugar_import(import_framework):
#TODO attendees
def import_meeting(self, val):
attendee_id = self.get_attendee_id(self.cr, self.uid, 'Meetings', val.get('id')) #TODO
attendee_id = self.get_attendee_id(self.cr, self.uid, 'Meetings', val.get('id')) #TODO
val['attendee_ids/id'] = attendee_id
return val
def get_meeting_mapping(self):
return {
'model' : 'crm.meeting',
'dependencies' : [self.TABLE_CONTACT, self.TABLE_OPPORTUNITY, self.TABLE_LEAD, self.TABLE_COMPAIGN],
'dependencies' : [self.TABLE_CONTACT, self.TABLE_OPPORTUNITY, self.TABLE_LEAD],
'hook': self.import_meeting,
'map' : {
'name': 'name',
@ -561,7 +575,7 @@ class sugar_import(import_framework):
def get_opp_mapping(self):
return {
'model' : 'crm.lead',
'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT],
'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT,self.TABLE_COMPAIGN],
'hook' : self.import_opp,
'map' : {
'name': 'name',
@ -859,15 +873,16 @@ class sugar_import(import_framework):
}
class import_sugarcrm(osv.osv):
"""Import SugarCRM DATA"""
_name = "import.sugarcrm"
_description = __doc__
_columns = {
'username': fields.char('User Name', size=64, required=True),
'password': fields.char('Password', size=24,required=True),
'url' : fields.char('Service', size=264, required=True, help="Connection with Sugarcrm Using Soap Protocol Services and For that Path should be 'http://localhost/sugarcrm/soap.php' Format."),
'opportunity': fields.boolean('Leads and Opportunities', help="If Opportunities are checked, SugarCRM opportunities data imported in OpenERP crm-Opportunity form"),
'user': fields.boolean('Users', help="If Users are checked, SugarCRM Users data imported in OpenERP Users form"),
@ -884,8 +899,9 @@ class import_sugarcrm(osv.osv):
'bug': fields.boolean('Bugs', help="If Bugs is checked, SugarCRM Bugs data imported in OpenERP Project Issues form"),
'attachment': fields.boolean('Attachments', help="If Attachments is checked, SugarCRM Notes data imported in OpenERP's Related module's History with attachment"),
'document': fields.boolean('Documents', help="If Documents is checked, SugarCRM Documents data imported in OpenERP Document Form"),
'username': fields.char('User Name', size=64),
'password': fields.char('Password', size=24),
'email_from': fields.char('Notify End Of Import To:', size=128),
'instance_name': fields.char("Instance's Name", size=64, help="Prefix of SugarCRM id to differentiate xml_id of SugarCRM models datas come from different server."),
}
_defaults = {#to be set to true, but easier for debugging
'opportunity': False,
@ -901,7 +917,10 @@ class import_sugarcrm(osv.osv):
'project' : False,
'project_task': False,
'bug': False,
'document': False
'document': False,
'username' : 'tfr',
'password' : 'a',
'url': "http://localhost/sugarcrm/soap.php"
}
def get_key(self, cr, uid, ids, context=None):
@ -910,6 +929,7 @@ class import_sugarcrm(osv.osv):
context = {}
key_list = []
for current in self.browse(cr, uid, ids, context):
context.update({'username': current.username, 'password': current.password, 'url': current.url, 'email_user': current.email_from or False, 'instance_name': current.instance_name or False})
if current.opportunity:
key_list.append('Leads')
key_list.append('Opportunities')
@ -943,11 +963,51 @@ class import_sugarcrm(osv.osv):
key_list.append('DocumentRevisions')
return key_list
def do_import_all(self, cr, uid, *args):
"""
scheduler Method
"""
imported = set()
context = {}
login_obj = self.pool.get('sugarcrm.login')
if args[1]:
login_id = login_obj.browse(cr, uid, args[1])
context.update({'username': login_id.username, 'password': login_id.password, 'url': login_id.url, 'instance_name': args[3]})
for key in args[0]:
imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", [context.get('email_from', 'tfr@openerp.com')], context)
imp.set_table_list(keys)
imp.start()
return True
def import_from_scheduler_all(self, cr, uid, ids, context=None):
keys = self.get_key(cr, uid, ids, context)
if not keys:
raise osv.except_osv(_('Warning !'), _('Select Module to Import.'))
cron_obj = self.pool.get('ir.cron')
mod_obj = self.pool.get('ir.model.data')
login_obj = self.pool.get('sugarcrm.login')
field = ['username', 'password', 'url']
datas = [context.get('username'), context.get('password'), context.get('url')]
name = 'login_user_'+ context.get('username')
self.import_object(fields, datas, 'sugarcrm.login', 'sugarcrm_login', name, [('username', '=', context.get('username'))])
login_id = self.xml_id_exist('sugarcrm_login', name)
args = (keys, login_id, context.get('email_user'), context.get('instance_name'))
for current in self.browse(cr, uid, ids):
new_create_id = cron_obj.create(cr, uid, {'name': 'Import SugarCRM datas','interval_type': 'hours','interval_number': 1, 'numbercall': -1,'model': 'import.sugarcrm','function': 'do_import_sugarcrm_data', 'args': args, 'active': False})
return {
'name': 'SugarCRM Scheduler',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'ir.cron',
'res_id': new_create_id,
'type': 'ir.actions.act_window',
}
def import_all(self, cr, uid, ids, context=None):
# """Import all sugarcrm data into openerp module"""
keys = self.get_key(cr, uid, ids, context)
imp = sugar_import(self, cr, uid, "sugarcrm", "import_sugarcrm", ["tfr@openerp.com"], context)
imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", [context.get('email_from', 'tfr@openerp.com')], context)
imp.set_table_list(keys)
imp.start()

View File

@ -8,28 +8,62 @@
<field name="model">import.sugarcrm</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import SugarCRM">
<form string="Import Data From SugarCRM">
<group colspan="4" width="700">
<separator string="Select SugarCRM Module Name" colspan="4"/>
<separator string="Login Information" colspan="4"/>
<field name="url" colspan="4" widget="url"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
<separator string="Choose Data You Want to Import" colspan="4"/>
<group colspan="4" col="6">
<field name="opportunity" />
<field name= "meeting" />
<field name= "task" string="Meeting Tasks"/>
<field name= "call" />
<field name= "claim" />
<field name= "account" />
<field name= "contact" />
<field name="user" />
<field name= "employee" />
<field name= "email" />
<field name= "project" />
<field name= "project_task" />
<field name= "bug" string="Project Issue"/>
<field name= "document" />
<field name= "attachment" string="History and Attachment" />
</group>
<field name="username" invisible="1"/>
<field name="password" invisible="1"/>
<group colspan="2" col="3">
<separator string="Module: CRM" colspan="4"/>
<field name="opportunity" />
<field name= "meeting" />
<field name= "task" string="Meeting Tasks"/>
<field name= "call" />
<field name= "claim" />
<field name= "email" />
</group>
<group colspan="2" col="2">
<separator string="Module: HR" colspan="4"/>
<field name= "employee" />
</group>
<newline/>
<group colspan="2" col="3">
<separator string="Module: Base" colspan="4"/>
<field name= "account" />
<field name= "contact" />
<field name="user" />
</group>
<group colspan="2" col="3">
<separator string="Module: Project" colspan="4"/>
<field name= "project" />
<field name= "project_task" />
<field name= "bug" string="Project Issue"/>
</group>
<newline/>
<group colspan="2" col="3">
<separator string="Module: Document" colspan="4"/>
<field name= "document" />
<field name= "attachment" string="History and Attachment" />
</group>
</group>
<group colspan="4">
<separator string="Email Notification When Import is finished" colspan="4"/>
<field name="email_from" widget="email" string="Email Address to Notify" colspan="4"/>
</group>
<group colspan="4">
<separator string="Multi Instance Management" colspan="4"/>
<field name="instance_name" colspan="4"/>
</group>
<group colspan="4">
<separator string="" colspan="4"/>
<button name="import_from_scheduler_all" string="Create Recurrent Report"
type="object" icon="terp-camera_test"/>
</group>
</group>
<separator string="" colspan="4" />
<group colspan="4" >
@ -53,6 +87,8 @@
<field name="target">new</field>
</record>
<menuitem name="SugarCRM" id="menu_sugarcrm" parent="base.menu_base_partner"/>
<menuitem name="Import SugarCRM" id="menu_sugarcrm_import" parent="menu_sugarcrm" action="action_import_sugarcrm" icon="STOCK_EXECUTE"/>
</data>
</openerp>

View File

@ -38,25 +38,4 @@ class sugarcrm_login(osv.osv):
'url': "http://localhost/sugarcrm/soap.php"
}
def open_import(self, cr, uid, ids, context=None):
for current in self.browse(cr, uid, ids, context):
PortType,sessionid = sugar.login(current.username, current.password, current.url)
if sessionid == '-1':
raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
obj_model = self.pool.get('ir.model.data')
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','import.sugarcrm.form')])
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
context.update({'rec_id': ids, 'username': current.username, 'password': current.password, 'url': current.url})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'import.sugarcrm',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'context': context
}
sugarcrm_login()

View File

@ -27,20 +27,6 @@
</field>
</record>
<!-- Sugarcrm Login Action -->
<record model="ir.actions.act_window" id="action_sugarcrm_login">
<field name="name">SugarCRM Login</field>
<field name="res_model">sugarcrm.login</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_sugarcrm_login_form"/>
<field name="target">new</field>
</record>
<menuitem name="SugarCRM" id="menu_sugarcrm" parent="base.menu_base_partner"/>
<menuitem name="Import SugarCRM" id="menu_sugarcrm_login" parent="menu_sugarcrm" action="action_sugarcrm_login" icon="STOCK_EXECUTE"/>
</data>
</openerp>