[IMP]: Add Login wizard for sugarcrm
bzr revid: atp@tinyerp.com-20110217072142-tbkn8lqjyr5tfj2r
This commit is contained in:
parent
cba7c6344b
commit
b2954d23c0
|
@ -21,3 +21,4 @@
|
|||
|
||||
import import_sugarcrm
|
||||
import sugar
|
||||
import wizard
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
'website': 'http://www.openerp.com',
|
||||
'depends': [],
|
||||
'init_xml': [],
|
||||
'update_xml': ["import_sugarcrm_view.xml"],
|
||||
'update_xml': ["wizard/sugarcrm_login_view.xml",
|
||||
"wizard/import_message_view.xml",
|
||||
"import_sugarcrm_view.xml"],
|
||||
'demo_xml': [],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
|
|
|
@ -35,6 +35,8 @@ class import_sugarcrm(osv.osv):
|
|||
('accounts','Accounts'),
|
||||
('contact','Contacts'),
|
||||
],'Module Name', help="Module Name is used to specify which Module data want to Import"),
|
||||
'username': fields.char('User Name', size=64),
|
||||
'password': fields.char('Password', size=24),
|
||||
}
|
||||
|
||||
def _get_all(self, cr, uid, model, sugar_val, context=None):
|
||||
|
@ -57,6 +59,7 @@ class import_sugarcrm(osv.osv):
|
|||
|
||||
def _create_lead(self, cr, uid, sugar_val, country, state, context=None):
|
||||
lead_pool = self.pool.get("crm.lead")
|
||||
|
||||
stage_id = ''
|
||||
stage_pool = self.pool.get('crm.case.stage')
|
||||
if sugar_val.get('status','') == 'New':
|
||||
|
@ -156,7 +159,6 @@ class import_sugarcrm(osv.osv):
|
|||
def import_data(self, cr, uid, ids,context=None):
|
||||
if not context:
|
||||
context={}
|
||||
|
||||
for current in self.browse(cr, uid, ids):
|
||||
if current.mod_name == 'lead' or current.mod_name == 'opportunity':
|
||||
module_name = 'crm'
|
||||
|
@ -179,20 +181,32 @@ class import_sugarcrm(osv.osv):
|
|||
sugar_name="Accounts"
|
||||
elif current.mod_name == 'contact':
|
||||
sugar_name="Contacts"
|
||||
|
||||
sugar_data = sugar.test(sugar_name)
|
||||
for sugar_val in sugar_data:
|
||||
country = self._get_all_countries(cr, uid, sugar_val.get('primary_address_country'), context)
|
||||
state = self._get_all_states(cr, uid, sugar_val.get('primary_address_state'), context)
|
||||
if sugar_name == "Leads":
|
||||
self._create_lead(cr, uid, sugar_val, country, state, context)
|
||||
|
||||
elif sugar_name == "Opportunities":
|
||||
self._create_opportunity(cr, uid, sugar_val, country, state,context)
|
||||
|
||||
elif sugar_name == "Contacts":
|
||||
self._create_contact(cr, uid, sugar_val, country, state, context)
|
||||
return {}
|
||||
PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
|
||||
sugar_data = sugar.search(PortType,sessionid,sugar_name)
|
||||
if sugar_data:
|
||||
for sugar_val in sugar_data:
|
||||
country = self._get_all_countries(cr, uid, sugar_val.get('primary_address_country'), context)
|
||||
state = self._get_all_states(cr, uid, sugar_val.get('primary_address_state'), context)
|
||||
if sugar_name == "Leads":
|
||||
self._create_lead(cr, uid, sugar_val, country, state, context)
|
||||
|
||||
elif sugar_name == "Opportunities":
|
||||
self._create_opportunity(cr, uid, sugar_val, country, state,context)
|
||||
|
||||
elif sugar_name == "Contacts":
|
||||
self._create_contact(cr, uid, sugar_val, country, state, context)
|
||||
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','import.message.form')])
|
||||
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'import.message',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
import_sugarcrm()
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
<group colspan="4" >
|
||||
<separator string="Select SugarCRM Module Name" colspan="4"/>
|
||||
<field name="mod_name" />
|
||||
<field name="username" invisible="1"/>
|
||||
<field name="password" invisible="1"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" >
|
||||
|
@ -35,8 +37,6 @@
|
|||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem name="Sugarcrm" id="menu_sugarcrm" parent="base.menu_base_partner"/>
|
||||
<menuitem name="Import Sugarcrm" id="menu_import_sugarcrm" parent="menu_sugarcrm" action="action_import_sugarcrm" icon="STOCK_EXECUTE"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,97 +1,42 @@
|
|||
|
||||
import hashlib
|
||||
from sugarsoap_services import *
|
||||
from sugarsoap_services_types import *;
|
||||
|
||||
import sys;
|
||||
|
||||
class LoginError(Exception): pass
|
||||
|
||||
class SugarCRM:
|
||||
def __init__(self, url=None, tracefile=None):
|
||||
loc = sugarsoapLocator()
|
||||
self.portType = loc.getsugarsoapPortType(url=url,
|
||||
tracefile=tracefile)
|
||||
self.sessid = None
|
||||
def login(username, password):
|
||||
loc = sugarsoapLocator();
|
||||
|
||||
def login(self, username, password):
|
||||
request = loginRequest()
|
||||
uauth = request.new_user_auth()
|
||||
request.User_auth = uauth
|
||||
portType = loc.getsugarsoapPortType();
|
||||
request = loginRequest();
|
||||
uauth = ns0.user_auth_Def(request);
|
||||
request._user_auth = uauth;
|
||||
|
||||
uauth.User_name = username
|
||||
uauth.Password = hashlib.md5(password).hexdigest()
|
||||
uauth.Version = "1.1"
|
||||
uauth._user_name = username;
|
||||
uauth._password = hashlib.md5(password).hexdigest();
|
||||
uauth._version = '1.1';
|
||||
|
||||
response = self.portType.login(request)
|
||||
if -1 == response.Return.Id:
|
||||
raise LoginError(response.Return.Error)
|
||||
self.sessid = response.Return.Id
|
||||
response = portType.login(request);
|
||||
if -1 == response._return._id:
|
||||
raise LoginError(response._return._error._description);
|
||||
return (portType, response._return._id);
|
||||
|
||||
def logout(self):
|
||||
if None == self.sessid:
|
||||
return
|
||||
request = logoutRequest()
|
||||
request.Session = self.sessid
|
||||
|
||||
self.portType.logout(request)
|
||||
self.sessid = None
|
||||
|
||||
def _get_sugar_user_id(self):
|
||||
gui_req = get_user_idRequest()
|
||||
gui_req.Session = self.sessid
|
||||
uid = self.portType.get_user_id(gui_req).Return
|
||||
self.sugar_user_id = uid
|
||||
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if "sugar_user_id" == attr:
|
||||
self._get_sugar_user_id()
|
||||
return self.sugar_user_id
|
||||
else:
|
||||
raise AttributeError
|
||||
|
||||
class SugarModule:
|
||||
def __init__(self, sugar, module_name, encoding='utf-8'):
|
||||
self.module_name = module_name
|
||||
self.sugar = sugar
|
||||
self.encoding = encoding
|
||||
|
||||
def search(self, entryid, fields=None):
|
||||
from sugarsoap_services import get_entry_listRequest
|
||||
se_req = get_entry_listRequest()
|
||||
se_req._session = self.sugar.sessid
|
||||
se_req._module_name = self.module_name
|
||||
sugarcrm_obj = SugarCRM("http://localhost/sugarcrm/soap.php")
|
||||
portType = sugarcrm_obj.portType
|
||||
se_resp = portType.get_entry_list(se_req);
|
||||
list = se_resp._return._entry_list;
|
||||
ans_list = []
|
||||
for i in list:
|
||||
ans_dir = {};
|
||||
for j in i._name_value_list:
|
||||
ans_dir[j._name.encode(self.encoding)] = j._value.encode(self.encoding)
|
||||
#end for
|
||||
ans_list.append(ans_dir);
|
||||
def search(portType, sessionid, module_name=None):
|
||||
se_req = get_entry_listRequest();
|
||||
se_req._session = sessionid
|
||||
se_req._module_name = module_name
|
||||
se_resp = portType.get_entry_list(se_req);
|
||||
list = se_resp._return._entry_list;
|
||||
ans_list = []
|
||||
for i in list:
|
||||
ans_dir = {};
|
||||
for j in i._name_value_list:
|
||||
ans_dir[j._name.encode('utf-8')] = j._value.encode('utf-8')
|
||||
#end for
|
||||
return ans_list;
|
||||
|
||||
def test(module_name):
|
||||
sugarcrm_obj = SugarCRM("http://localhost/sugarcrm/soap.php")
|
||||
sugar_login = sugarcrm_obj.login('sarah', 'sarah')
|
||||
sugarmodule_obj = SugarModule(sugarcrm_obj, module_name)
|
||||
vals = sugarmodule_obj.search(sugarcrm_obj)
|
||||
return vals
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ans_list.append(ans_dir);
|
||||
#end for
|
||||
return ans_list;
|
||||
|
||||
|
|
|
@ -213,7 +213,10 @@ class sugarsoapBindingSOAP:
|
|||
self.binding.Send(None, None, request, soapaction="http://localhost/sugarcrm/soap.php/get_entry_list", encodingStyle="http://schemas.xmlsoap.org/soap/encoding/", **kw)
|
||||
# no output wsaction
|
||||
typecode = Struct(pname=None, ofwhat=get_entry_listResponse.typecode.ofwhat, pyclass=get_entry_listResponse.typecode.pyclass)
|
||||
response = self.binding.Receive(typecode)
|
||||
try:
|
||||
response = self.binding.Receive(typecode)
|
||||
except:
|
||||
return None
|
||||
return response
|
||||
|
||||
# op: get_entry
|
||||
|
|
Loading…
Reference in New Issue