本文整理汇总了Python中melisdk.meli.Meli类的典型用法代码示例。如果您正苦于以下问题:Python Meli类的具体用法?Python Meli怎么用?Python Meli使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Meli类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: product_get_meli_loginstate
def product_get_meli_loginstate( self, cr, uid, ids, field_name, attributes, context=None ):
# recoger el estado y devolver True o False (meli)
#False if logged ok
#True if need login
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
ML_state = False
if ACCESS_TOKEN=='':
ML_state = True
else:
response = meli.get("/users/me/", {'access_token':meli.access_token} )
rjson = response.json()
if 'error' in rjson:
if rjson['message']=='invalid_token' or rjson['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
ML_state = True
#raise osv.except_osv( _('MELI WARNING'), _('INVALID TOKEN (must login, go to Edit Company and login): error: %s, message: %s, status: %s') % ( rjson["error"], rjson["message"],rjson["status"],))
res = {}
for product in self.browse(cr,uid,ids):
res[product.id] = ML_state
return res
示例2: index
def index(self, **codes):
cr, uid, context = request.cr, request.uid, request.context
company = request.registry.get("res.company").browse(cr, uid, 1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
meli = Meli(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
codes.setdefault("code", "none")
codes.setdefault("error", "none")
codes.setdefault("error_description", "none")
if codes["error"] != "none":
message = "ERROR: %s" % codes["error"]
message += " DESCRIPTION: %s" % codes["error_description"]
return "<h1>" + message + "</h1><br/><a href='" + meli.auth_url(redirect_URI=REDIRECT_URI) + "'>Login</a>"
if codes["code"] != "none":
print "Meli: Authorize: REDIRECT_URI: %s, code: %s" % (REDIRECT_URI, codes["code"])
meli.authorize(codes["code"], REDIRECT_URI)
ACCESS_TOKEN = meli.access_token
REFRESH_TOKEN = meli.refresh_token
company.write(
{
"mercadolibre_access_token": ACCESS_TOKEN,
"mercadolibre_refresh_token": REFRESH_TOKEN,
"mercadolibre_code": codes["code"],
}
)
return (
'LOGGED WIT CODE: %s <br>ACCESS_TOKEN: %s <br>REFRESH_TOKEN: %s <br>MercadoLibre for Odoo 8 - Moldeo Interactive <br><a href="javascript:window.history.go(-2);">Volver a Odoo</a> <script>window.history.go(-2)</script>'
% (codes["code"], ACCESS_TOKEN, REFRESH_TOKEN)
)
else:
return "<a href='" + meli.auth_url(redirect_URI=REDIRECT_URI) + "'>Login</a>"
示例3: product_meli_delete
def product_meli_delete( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
if product.meli_status!='closed':
self.product_meli_status_close( cr, uid, ids, context )
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.put("/items/"+product.meli_id, { 'deleted': 'true' }, {'access_token':meli.access_token})
#print "product_meli_delete: " + response.content
rjson = response.json()
ML_status = rjson["status"]
if "error" in rjson:
ML_status = rjson["error"]
if "sub_status" in rjson:
if len(rjson["sub_status"]) and rjson["sub_status"][0]=='deleted':
product.write({ 'meli_id': '' })
return {}
示例4: product_post
def product_post(self, cr, uid, ids, context=None):
product_ids = context['active_ids']
product_obj = self.pool.get('product.product')
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
#user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get('warning')
#company = self.pool.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if ACCESS_TOKEN=='':
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
for product_id in product_ids:
product = product_obj.browse(cr,uid,product_id)
product.product_meli_post()
return {}
示例5: product_get_meli_status
def product_get_meli_status( self, cr, uid, ids, field_name, attributes, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
warningobj = self.pool.get('warning')
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
ML_status = "unknown"
if ACCESS_TOKEN=='':
ML_status = "unknown"
else:
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if product.meli_id:
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token} )
rjson = response.json()
ML_status = rjson["status"]
if "error" in rjson:
ML_status = rjson["error"]
if "sub_status" in rjson:
if len(rjson["sub_status"]) and rjson["sub_status"][0]=='deleted':
product.write({ 'meli_id': '' })
res = {}
for product in self.browse(cr,uid,ids):
res[product.id] = ML_status
return res
示例6: orders_update_order
def orders_update_order( self, cr, uid, id, context=None ):
#get with an item id
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
order_obj = self.pool.get('mercadolibre.orders')
order_items_obj = self.pool.get('mercadolibre.order_items')
order = order_obj.browse(cr, uid, id )
log_msg = 'orders_update_order: %s' % (order.order_id)
_logger.info(log_msg)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN )
response = meli.get("/orders/"+order.order_id, {'access_token':meli.access_token})
order_json = response.json()
#_logger.info( product_json )
if "error" in order_json:
_logger.error( order_json["error"] )
_logger.error( order_json["message"] )
else:
self.orders_update_order_json( cr, uid, {"id": id, "order_json": order_json } )
return {}
示例7: get_meli_state
def get_meli_state( self, cr, uid, ids, field_name, attributes, context=None ):
# recoger el estado y devolver True o False (meli)
#False if logged ok
#True if need login
print 'company get_meli_state() '
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
warningobj = self.pool.get('warning')
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
ML_state = False
try:
response = meli.get("/items/MLA1", {'access_token':meli.access_token} )
print "response.content:", response.content
rjson = response.json()
#response = meli.get("/users/")
if "error" in rjson:
if "message" in rjson and rjson["message"]=="expired_token":
ML_state = True
if ACCESS_TOKEN=='':
ML_state = True
except requests.exceptions.ConnectionError as e:
#raise osv.except_osv( _('MELI WARNING'), _('NO INTERNET CONNECTION TO API.MERCADOLIBRE.COM: complete the Cliend Id, and Secret Key and try again'))
ML_state = True
error_msg = 'MELI WARNING: NO INTERNET CONNECTION TO API.MERCADOLIBRE.COM: complete the Cliend Id, and Secret Key and try again '
_logger.error(error_msg)
# except requests.exceptions.HTTPError as e:
# print "And you get an HTTPError:", e.message
if ML_state:
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
res = {}
for company in self.browse(cr,uid,ids):
res[company.id] = ML_state
return res
示例8: product_meli_upload_image
def product_meli_upload_image( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if product.image==None:
return { 'status': 'error', 'message': 'no image to upload' }
# print "product_meli_upload_image"
#print "product_meli_upload_image: " + response.content
imagebin = base64.b64decode(product.image)
imageb64 = product.image
# print "data:image/png;base64,"+imageb64
# files = [ ('images', ('image_medium', imagebin, "image/png")) ]
files = { 'file': ('image.png', imagebin, "image/png"), }
#print files
response = meli.upload("/pictures", files, { 'access_token': meli.access_token } )
# print response.content
rjson = response.json()
if ("error" in rjson):
raise osv.except_osv( _('MELI WARNING'), _('No se pudo cargar la imagen en MELI! Error: %s , Mensaje: %s, Status: %s') % ( rjson["error"], rjson["message"],rjson["status"],))
return { 'status': 'error', 'message': 'not uploaded'}
_logger.info( rjson )
if ("id" in rjson):
#guardar id
product.write( { "meli_imagen_id": rjson["id"], "meli_imagen_link": rjson["variations"][0]["url"] } )
#asociar imagen a producto
if product.meli_id:
response = meli.post("/items/"+product.meli_id+"/pictures", { 'id': rjson["id"] }, { 'access_token': meli.access_token } )
else:
return { 'status': 'warning', 'message': 'uploaded but not assigned' }
return { 'status': 'success', 'message': 'uploaded and assigned' }
示例9: index
def index(self):
cr, uid, context = request.cr, request.uid, request.context
company = request.registry.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
if (ACCESS_TOKEN==''):
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
return "<a href='"+meli.auth_url(redirect_URI=REDIRECT_URI)+"'>Login</a>"
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/MLA533830652")
return "MercadoLibre for Odoo 8 - Moldeo Interactive: %s " % response.content
示例10: product_meli_login
def product_meli_login(self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
#url_login_oerp = "/meli_login"
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
示例11: product_meli_get_product
def product_meli_get_product( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token})
#print "product_meli_get_product: " + response.content
return {}
示例12: product_meli_upload_multi_images
def product_meli_upload_multi_images( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if product.images==None:
return { 'status': 'error', 'message': 'no images to upload' }
image_ids = []
c = 0
#loop over images
for product_image in product.images:
if (product_image.image):
print "product_image.image:" + str(product_image.image)
imagebin = base64.b64decode( product_image.image )
#files = { 'file': ('image.png', imagebin, "image/png"), }
files = { 'file': ('image.jpg', imagebin, "image/jpeg"), }
response = meli.upload("/pictures", files, { 'access_token': meli.access_token } )
print "meli upload:" + response.content
rjson = response.json()
if ("error" in rjson):
raise osv.except_osv( _('MELI WARNING'), _('No se pudo cargar la imagen en MELI! Error: %s , Mensaje: %s, Status: %s') % ( rjson["error"], rjson["message"],rjson["status"],))
#return { 'status': 'error', 'message': 'not uploaded'}
else:
image_ids+= [ { 'id': rjson['id'] }]
c = c + 1
print "image_ids:" + str(image_ids)
product.write( { "meli_multi_imagen_id": "%s" % (image_ids) } )
return image_ids
示例13: product_meli_get_product
def product_meli_get_product( self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, ids[0])
product_template_obj = self.pool.get('product.template')
product_template = product_template_obj.browse(cr, uid, product.product_tmpl_id.id)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
response = meli.get("/items/"+product.meli_id, {'access_token':meli.access_token})
print "product_meli_get_product: " + response.content
rjson = response.json()
des = ''
desplain = ''
vid = ''
if 'error' in rjson:
return {}
#TODO: traer la descripcion: con
#https://api.mercadolibre.com/items/{ITEM_ID}/description?access_token=$ACCESS_TOKEN
if rjson['descriptions']:
response2 = meli.get("/items/"+product.meli_id+"/description", {'access_token':meli.access_token})
rjson2 = response2.json()
des = rjson2['text']
desplain = rjson2['plain_text']
if (len(des)>0):
desplain = des
#TODO: verificar q es un video
if rjson['video_id']:
vid = ''
#TODO: traer las imagenes
#TODO:
pictures = rjson['pictures']
if pictures and len(pictures):
thumbnail_url = pictures[0]['url']
image = urllib2.urlopen(thumbnail_url).read()
image_base64 = base64.encodestring(image)
product.image_medium = image_base64
#if (len(pictures)>1):
#complete product images:
#delete all images...
#categories
mlcatid = ""
if ('category_id' in rjson):
category_id = rjson['category_id']
ml_cat_id = self.pool.get('mercadolibre.category').search(cr,uid,[('meli_category_id','=',category_id)])
if (ml_cat_id):
print "category exists!" + str(ml_cat_id)
mlcatid = ml_cat_id[0]
else:
print "Creating category: " + str(category_id)
#https://api.mercadolibre.com/categories/MLA1743
response_cat = meli.get("/categories/"+str(category_id), {'access_token':meli.access_token})
rjson_cat = response_cat.json()
print "category:" + str(rjson_cat)
fullname = ""
if ("path_from_root" in rjson_cat):
path_from_root = rjson_cat["path_from_root"]
for path in path_from_root:
fullname = fullname + "/" + path["name"]
#fullname = fullname + "/" + rjson_cat['name']
print "category fullname:" + fullname
cat_fields = {
'name': fullname,
'meli_category_id': ''+str(category_id),
}
ml_cat_id = self.pool.get('mercadolibre.category').create(cr,uid,(cat_fields))
if (ml_cat_id):
mlcatid = ml_cat_id
imagen_id = ''
if (len(rjson['pictures'])>0):
imagen_id = rjson['pictures'][0]['id']
meli_fields = {
'name': str(rjson['title']),
'meli_imagen_id': imagen_id,
'meli_post_required': True,
'meli_id': rjson['id'],
'meli_permalink': rjson['permalink'],
'meli_title': rjson['title'],
'meli_description': desplain,
# 'meli_description_banner_id': ,
'meli_category': mlcatid,
'meli_listing_type': rjson['listing_type_id'],
'meli_buying_mode':rjson['buying_mode'],
'meli_price': str(rjson['price']),
#.........这里部分代码省略.........
示例14: product_meli_get_products
def product_meli_get_products( self, cr, uid, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
#product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
#url_login_oerp = "/meli_login"
results = []
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': 0 })
#response = meli.get("/sites/MLA/search?seller_id="+company.mercadolibre_seller_id+"&limit=0", {'access_token':meli.access_token})
rjson = response.json()
_logger.info( rjson )
results = rjson['results']
if 'error' in rjson:
if rjson['message']=='invalid_token' or rjson['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
#download?
if (rjson['paging']['total']>rjson['paging']['limit']):
pages = rjson['paging']['total']/rjson['paging']['limit']
ioff = rjson['paging']['limit']
condition_last_off = False
while (condition_last_off!=True):
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': ioff })
rjson2 = response.json()
if 'error' in rjson2:
if rjson2['message']=='invalid_token' or rjson2['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
condition = True
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
else:
results += rjson2['results']
ioff+= rjson['paging']['limit']
condition_last_off = ( ioff>=rjson['paging']['total'])
_logger.info( rjson )
_logger.info( "("+str(rjson['paging']['total'])+") products to check...")
iitem = 0
if (results):
for item_id in results:
print item_id
iitem+= 1
_logger.info( item_id + "("+str(iitem)+"/"+str(rjson['paging']['total'])+")" )
posting_id = self.pool.get('product.product').search(cr,uid,[('meli_id','=',item_id)])
response = meli.get("/items/"+item_id, {'access_token':meli.access_token})
rjson3 = response.json()
if (posting_id):
_logger.info( "Item already in database: " + str(posting_id[0]) )
#print "Item already in database: " + str(posting_id[0])
else:
idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['title'], 'meli_id': rjson3['id'] })
#idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['id'], 'description': rjson3['title'], 'meli_id': rjson3['id'] })
if (idcreated):
_logger.info( "product created: " + str(rjson3['id']) + "-" + str( rjson3['title']) )
product = product_obj.browse(cr, uid, idcreated)
product_obj.product_meli_get_product( cr, uid, [idcreated] )
return {}
示例15: orders_query_iterate
def orders_query_iterate( self, cr, uid, offset=0, context=None ):
offset_next = 0
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
orders_obj = self.pool.get('mercadolibre.orders')
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
#
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN )
orders_query = "/orders/search?seller="+company.mercadolibre_seller_id+"&sort=date_desc"
if (offset):
orders_query = orders_query + "&offset="+str(offset).strip()
response = meli.get( orders_query, {'access_token':meli.access_token})
orders_json = response.json()
if "error" in orders_json:
_logger.error( orders_query )
_logger.error( orders_json["error"] )
if (orders_json["message"]=="invalid_token"):
_logger.error( orders_json["message"] )
return {}
_logger.info( orders_json )
#testing with json:
if (True==False):
with open('/home/fabricio/envOdoo8/sources/meli_oerp/orders.json') as json_data:
_logger.info( json_data )
orders_json = json.load(json_data)
_logger.info( orders_json )
if "paging" in orders_json:
if "total" in orders_json["paging"]:
if (orders_json["paging"]["total"]==0):
return {}
else:
if (orders_json["paging"]["total"]==orders_json["paging"]["limit"]):
offset_next = offset + orders_json["paging"]["limit"]
if "results" in orders_json:
for order_json in orders_json["results"]:
if order_json:
self.orders_update_order_json( cr, uid, {"id": False, "order_json": order_json} )
if (offset_next>0):
self.orders_query_iterate(cr,uid,offset_next)
return {}