39
39
def __init__(self, location, username, password, debug=False):
40
40
#Append / if not there
41
41
if not location[-1] == '/':
43
43
self.corelocation = location
44
44
#Please do not remove the str indeed xmlrpc lib require a string for the location
45
45
#if an unicode is send it will raise you an error
48
48
self.password = password
51
self.logger = netsvc.Logger()
51
self.logger = logging.getLogger('Connection(%s)' % self.location)
55
55
if not self.location[-1] == '/':
56
56
self.location += '/'
58
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Attempting connection with Settings:%s,%s,%s") % (self.location, self.username, self.password))
58
self.logger.info(_("Attempting connection with Settings:%s,%s,%s"), self.location, self.username, self.password)
59
59
self.ser = xmlrpclib.ServerProxy(self.location)
60
60
for sleep_time in [1, 3, 6]:
62
62
self.session = self.ser.login(self.username, self.password)
64
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Login Successful"))
64
self.logger.info(_("Login Successful"))
67
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Error in connecting:%s") % (e))
68
self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time))
67
self.logger.error(_("Error in connecting:%s"), e, exc_info=True)
68
self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
69
69
time.sleep(sleep_time)
70
70
except Exception,e:
71
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_ERROR, _("Error in connecting:%s") % (e))
72
self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time))
73
time.sleep(sleep_time)
74
raise osv.except_osv(_('User Error'), _('Error when try to connect to magento, are your sure that your login is right? Did openerp can access to your magento?'))
77
def call(self, method, *arguments):
71
self.logger.error(_("Error in connecting:%s"), e, exc_info=True)
72
self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
73
time.sleep(sleep_time)
74
raise osv.except_osv(_('User Error'), _('Error connecting to magento, are your sure that your login is right? Did you configure API user in magento?'))
77
def call(self, method, *arguments):
79
79
arguments = list(arguments)[0]
82
82
for sleep_time in [1, 3, 6]:
85
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Calling Method:%s,Arguments:%s") % (method, arguments))
85
self.logger.info(_("Calling Method:%s,Arguments:%s"), method, arguments)
86
86
res = self.ser.call(self.session, method, arguments)
88
88
if method=='catalog_product.list':
89
89
# the response of the method catalog_product.list can be very very long so it's better to see it only if debug log is activate
90
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_DEBUG, _("Query Returned:%s") % (res))
90
self.logger.debug(_("Query Returned:%s"), res)
92
self.logger.notifyChannel(_("Magento Connection"), netsvc.LOG_INFO, _("Query Returned:%s") % (res))
92
self.logger.info(_("Query Returned:%s"), res)
95
self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_ERROR, _("Method: %s\nArguments:%s\nError:%s") % (method, arguments, e))
96
self.logger.notifyChannel(_("Magento Call"), netsvc.LOG_WARNING, _("Webservice Failure, sleeping %s second before next attempt") % (sleep_time))
95
self.logger.error(_("Method: %s\nArguments:%s\nError:%s"), method, arguments, e, exc_info=True)
96
self.logger.warn(_("Webservice Failure, sleeping %s second before next attempt"), sleep_time)
97
97
time.sleep(sleep_time)
118
118
_DELETE_METHOD = False
122
122
#TODO deprecated, remove use
123
123
def mage_to_oe(self, cr, uid, mageid, instance, *arguments):
124
124
"""given a record id in the Magento referential, returns a tuple (id, name) with the id in the OpenERP referential; Magento instance wise"""
143
143
read = self.read(cr, uid, oeid, [self._rec_name])
144
144
return (read[0]['id'], read[0][self._rec_name])
147
147
#TODO deprecated, remove use
148
148
def sync_import(self, cr, uid, magento_records, instance, debug=False, defaults=None, *attrs):
216
216
self.record_save(cr, uid, rec_id, vals, defaults)
218
218
self.record_save(cr, uid, rec_id, vals, defaults)
220
220
def record_save(self, cr, uid, rec_id, vals, defaults):
222
222
for key in defaults.keys():
228
228
#Record is not there, create it
229
229
self.create(cr, uid, vals,)
231
231
def cast_string(self, subject):
232
232
"""This function will convert string objects to the data type required. Example "0"/"1" to boolean conversion"""
233
233
for key in subject.keys():
259
259
list_method = self.pool.get('external.mapping').read(cr,uid,mapping_id[0],['external_list_method']).get('external_list_method',False)
261
261
data = conn.call(list_method, context['ids_or_filter'])
263
263
#it may happen that list method doesn't provide enough information, forcing us to use get_method on each record (case for sale orders)
264
264
if context.get('one_by_one', False):
265
265
self.mage_import_one_by_one(cr, uid, conn, external_referential_id, mapping_id[0], data, defaults, context)
337
337
self.sync_import(cr, uid, magento_records, instance, debug, defaults)
339
339
raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!"))
341
341
#TODO deprecated, remove use
342
342
def get_all_mage_ids(self, cr, uid, ids, instance=False):
343
343
search_param = []