[IMP]: Improve view, Add default address to account, Add document attachment.

bzr revid: atp@tinyerp.com-20110603141911-hmdo6mqlsxa28vu2
This commit is contained in:
Atul Patel (OpenERP) 2011-06-03 19:49:11 +05:30
parent cd56eed7f7
commit 1ba16a6ea5
4 changed files with 198 additions and 72 deletions

View File

@ -60,6 +60,7 @@ class sugar_import(import_framework):
TABLE_NOTE = 'Notes'
TABLE_EMAIL = 'Emails'
TABLE_COMPAIGN = 'Campaigns'
TABLE_DOCUMENT = 'DocumentRevisions'
TABLE_HISTORY_ATTACHMNET = 'history_attachment'
def initialize(self):
@ -71,7 +72,7 @@ class sugar_import(import_framework):
self.context['session_id'] = sessionid
def get_data(self, table):
return sugar.search(self.context.get('port'), self.context.get('session_id'), table)
return sugar.search(self.context.get('port'), self.context.get('session_id'), table, 0, 500)
"""
Common import method
"""
@ -111,6 +112,29 @@ class sugar_import(import_framework):
min = int(min) * 100 / 60
return "%s.%i" % (hour, min)
"""
import Documents
"""
def import_document(self, val):
File,Filename = sugar.get_document_revision_search(self.context.get('port'), self.context.get('session_id'), val.get('id'))
val['datas'] = base64.encodestring(File)
val['datas_fname'] = Filename
return val
def get_document_mapping(self):
return {
'model' : 'ir.attachment',
'dependencies' : [self.TABLE_USER],
'hook' : self.import_document,
'map' : {'name':'filename',
'description': ppconcat('description'),
'datas': 'datas',
'datas_fname': 'datas_fname',
}
}
"""
import Emails
"""
@ -126,7 +150,9 @@ class sugar_import(import_framework):
return attach_xml_id
def import_email(self, val):
val = sugar.email_search(self.context.get('port'), self.context.get('session_id'), self.TABLE_EMAIL, val.get('id'))
model_obj = self.obj.pool.get('ir.model.data')
val = val[0]
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:
@ -593,7 +619,6 @@ class sugar_import(import_framework):
'Dead': 'done',
'Converted': 'done',
}
def import_lead(self, val):
if val.get('opportunity_id'): #if lead is converted into opp, don't import as lead
@ -640,6 +665,12 @@ class sugar_import(import_framework):
"""
import contact
"""
def get_email(self, val):
email_address = sugar.get_contact_by_email(self.context.get('port'), self.context.get('username'), self.context.get('password'), val.get('email1'))
if email_address:
return ','.join(email_address)
def import_contact(self, val):
if val.get('primary_address_country'):
country_id = self.get_all_countries(val.get('primary_address_country'))
@ -665,7 +696,7 @@ class sugar_import(import_framework):
'city': 'primary_address_city',
'country_id/id': 'country_id/id',
'state_id/id': 'state_id/id',
'email': concat('email1', 'email2', delimiter=','),
'email': self.get_email,
'type': const('contact')
}
}
@ -673,37 +704,46 @@ class sugar_import(import_framework):
"""
import Account
"""
def get_address_type(self, val, type):
if type == 'invoice':
type_address = 'billing'
else:
type_address = 'shipping'
map_partner_address = {
type_address = 'shipping'
if type == 'default':
map_partner_address = {
'name': 'name',
'phone': 'phone_office',
'mobile': 'phone_mobile',
'fax': 'phone_fax',
'type': 'type',
'street': type_address + '_address_street',
'zip': type_address +'_address_postalcode',
'city': type_address +'_address_city',
'country_id/id': 'country_id/id',
'type': 'type',
'type': type,
'email': 'email1'
}
else:
map_partner_address = {
'name': 'name',
'phone': 'phone_office',
'mobile': 'phone_mobile',
'fax': 'phone_fax',
'type': 'type',
'street': type_address + '_address_street',
'zip': type_address +'_address_postalcode',
'city': type_address +'_address_city',
'country_id/id': 'country_id/id',
'type': 'type',
}
if val.get(type_address +'_address_country'):
country_id = self.get_all_countries(val.get(type_address +'_address_country'))
state = self.get_all_states(val.get(type_address +'_address_state'), country_id)
val['country_id/id'] = country_id
val['state_id/id'] = state
val['type'] = type
val['id_new'] = val['id'] + '_address_' + type
return self.import_object_mapping(map_partner_address, val, 'res.partner.address', self.TABLE_CONTACT, val['id_new'], self.DO_NOT_FIND_DOMAIN)
def get_partner_address(self, val):
address_id=[]
type_dict = {'billing_address_street' : 'invoice', 'shipping_address_street' : 'delivery'}
type_dict = {'billing_address_street' : 'invoice', 'shipping_address_street' : 'delivery', 'type': 'default'}
for key, type_value in type_dict.items():
if val.get(key):
id = self.get_address_type(val, type_value)
@ -838,6 +878,7 @@ class sugar_import(import_framework):
self.TABLE_CASE: self.get_crm_claim_mapping(),
self.TABLE_NOTE: self.get_history_mapping(),
self.TABLE_EMAIL: self.get_email_mapping(),
self.TABLE_DOCUMENT: self.get_document_mapping(),
self.TABLE_COMPAIGN: self.get_compaign_mapping()
}
@ -873,6 +914,7 @@ class import_sugarcrm(osv.osv):
'project': fields.boolean('Projects', help="If Projects is checked, SugarCRM Projects data imported in OpenERP Projects form"),
'project_task': fields.boolean('Project Tasks', help="If Project Tasks is checked, SugarCRM Project Tasks data imported in OpenERP Project Tasks form"),
'bug': fields.boolean('Bugs', help="If Bugs is checked, SugarCRM Bugs data imported in OpenERP Project Issues form"),
'document': fields.boolean('Documents', help="If Documents is checked, SugarCRM Documents data imported in OpenERP Document Form"),
'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."),
@ -889,6 +931,7 @@ class import_sugarcrm(osv.osv):
'project' : False,
'project_task': False,
'bug': False,
'document': False,
'instance_name': 'sugarcrm',
'email_from': 'tfr@openerp.com',
'username' : 'tfr',
@ -963,6 +1006,8 @@ class import_sugarcrm(osv.osv):
key_list.append('ProjectTask')
if current.bug:
key_list.append('Bugs')
if current.document:
key_list.append('DocumentRevisions')
return key_list

View File

@ -9,59 +9,72 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import Data From SugarCRM">
<group colspan="4" width="800">
<separator string="Login Information" colspan="4"/>
<field name="url" colspan="4" widget="url"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
<separator string="" colspan="4"/>
<group colspan="4" col="6">
<group colspan="1" col="2">
<separator string="Address Book" colspan="4"/>
<field name= "account" />
<field name= "contact" />
</group>
<group colspan="3" col="4">
<separator string="CRM" colspan="4"/>
<field name="opportunity" />
<field name= "meeting" />
<field name= "call" />
<field name= "claim" />
</group>
<group colspan="2" col="2">
<separator string="Project" colspan="4"/>
<field name= "project" />
<field name= "project_task" />
<field name= "bug"/>
</group>
<group colspan="1" col="2">
<separator string="HR" colspan="4"/>
<field name="employee" />
</group>
<group colspan="2" col="4">
<separator string="Document" colspan="4"/>
<field name="email_history"/>
</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"/>
</group>
<group colspan="4" groups="base.group_no_one">
<separator string="Multi Instance Management" colspan="4"/>
<field name="instance_name"/>
</group>
</group>
<separator string="" colspan="4" />
<group colspan="4" col="6">
<label string="" colspan="2"/>
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button name="import_from_scheduler_all" string="_Schedule recurrent import"
type="object" icon="gtk-execute"/>
<button name="import_all" string="_Import"
type="object" icon="terp-camera_test"/>
</group>
<group col="8">
<group colspan="2" col="1">
<label colspan="1" string=""/>
<label colspan="2" string="Explaination Text"/>
<label colspan="1" string="This Module Import SugarCRM Module Data into OpenERP Module."/>
<label colspan="2" />
<label colspan="2" string="Here is Document links:"/>
<label colspan="2" string="doc.openerp.com"/>
<label colspan="2" string=""/>
</group>
<separator string="" orientation="vertical" colspan="1" rowspan="24" />
<group colspan="4">
<separator string="Login Information" colspan="3"/>
<field name="url" colspan="4" widget="url"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
<separator string="" colspan="4"/>
<group colspan="4" col="6">
<group colspan="1" col="2">
<separator string="Address Book" colspan="4"/>
<field name= "account" />
<field name= "contact" />
</group>
<group colspan="1" col="1">
<separator string="CRM" colspan="4"/>
<field name="opportunity" />
<field name= "call" />
<field name= "meeting" />
<field name= "claim" />
<field name="email_history"/>
</group>
<group colspan="1" col="2">
<separator string="HR" colspan="4"/>
<field name="employee" />
</group>
<group colspan="2" col="2">
<separator string="Project" colspan="4"/>
<field name= "project" />
<field name= "project_task" />
<field name= "bug"/>
</group>
<group colspan="2" col="4">
<separator string="Document" colspan="4"/>
<field name= "document" />
</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"/>
</group>
<group colspan="4" groups="base.group_no_one">
<separator string="Multi Instance Management" colspan="4"/>
<field name="instance_name"/>
</group>
<separator string="" colspan="4" />
<group colspan="4" col="6">
<label string="" colspan="2"/>
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button name="import_from_scheduler_all" string="_Schedule recurrent import"
type="object" icon="gtk-execute"/>
<button name="import_all" string="_Import"
type="object" icon="terp-camera_test"/>
</group>
</group>
</group>
</form>
</field>
</record>

View File

@ -114,10 +114,50 @@ def get_contact_by_email(portType, username, password, email_address=None):
except Exception,e:
return 'Exception: %s\n' % (tools.ustr(e))
def search(portType, sessionid, module_name=None):
def get_document_revision_search(portType, sessionid, module_id=None):
se_req = get_document_revisionRequest()
se_req._session = sessionid
se_req._i = module_id
se_resp = portType.get_document_list(se_req)
file = False
filename = False
file = se_resp._return.Document_revision.File
filename = se_resp._return.Document_revision.Filename
return file, filename
def email_search(portType, sessionid, module_name, module_id, select_fields=None):
se_req = get_entryRequest()
se_req._session = sessionid
se_req._module_name = module_name
se_req._id = module_id
se_req._select_fields = select_fields
se_resp = portType.get_entry(se_req)
ans_list = []
if se_resp:
list = se_resp._return._entry_list
for i in list:
ans_dir = {}
for j in i._name_value_list:
ans_dir[tools.ustr(j._name)] = tools.ustr(j._value)
#end for
ans_list.append(ans_dir)
#end for
return ans_list
def search(portType, sessionid, module_name, offset, max_results, query=None, order_by=None, select_fields=None, deleted=None):
se_req = get_entry_listRequest()
se_req._session = sessionid
se_req._module_name = module_name
if query != None:
se_req._query = query
se_req._order_by = order_by
se_req._offset = offset
se_req._select_fields = select_fields
se_req._max_results = max_results
se_req._deleted = deleted
se_resp = portType.get_entry_list(se_req)
ans_list = []
if se_resp:

View File

@ -212,6 +212,18 @@ class sugarsoapBindingSOAP:
response = self.binding.Receive(typecode)
return response
#op: get_document_list
def get_document_list(self, request):
if isinstance(request, get_document_revisionRequest) is False:
raise TypeError, "%s incorrect request type" % (request.__class__)
kw = {}
# no input wsaction
self.binding.Send(None, None, request, soapaction="http://"+ IP +"/sugarcrm/soap.php/get_document_list", encodingStyle="http://schemas.xmlsoap.org/soap/encoding/", **kw)
# no output wsaction
typecode = Struct(pname=None, ofwhat=get_document_revisionResponse.typecode.ofwhat, pyclass=get_document_revisionResponse.typecode.pyclass)
response = self.binding.Receive(typecode)
return response
# op: get_entry_list
def get_entry_list(self, request):
if isinstance(request, get_entry_listRequest) is False:
@ -900,6 +912,22 @@ class get_entriesResponse:
get_entriesResponse.typecode.pyclass = get_entriesResponse
_set_entryRequestTypecode = Struct(pname=("http://www.sugarcrm.com/sugarcrm","set_entry"), ofwhat=[ZSI.TC.String(pname="session", aname="_session", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True), ZSI.TC.String(pname="module_name", aname="_module_name", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True), ns0.name_value_list_Def(pname="name_value_list", aname="_name_value_list", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True)], pyclass=None, encoded="http://www.sugarcrm.com/sugarcrm")
class get_document_revisionRequest:
def __init__(self):
self._session = None
self._i = None
return
get_document_revisionRequest.typecode = Struct(pname=("http://www.sugarcrm.com/sugarcrm","get_document_revision"), ofwhat=[ZSI.TC.String(pname="session", aname="_session", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True), ZSI.TC.String(pname="i", aname="_i", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True)], pyclass=get_document_revisionRequest, encoded="http://www.sugarcrm.com/sugarcrm")
class get_document_revisionResponse:
def __init__(self):
self._return = None
return
get_document_revisionResponse.typecode = Struct(pname=("http://www.sugarcrm.com/sugarcrm","get_document_revisionResponse"), ofwhat=[ns0.return_document_revision_Def(pname="return", aname="_return", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True)], pyclass=get_document_revisionResponse, encoded="http://www.sugarcrm.com/sugarcrm")
class set_entryRequest:
typecode = _set_entryRequestTypecode
__metaclass__ = pyclass_type