本文整理汇总了Python中melisdk.meli.Meli.post方法的典型用法代码示例。如果您正苦于以下问题:Python Meli.post方法的具体用法?Python Meli.post怎么用?Python Meli.post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类melisdk.meli.Meli
的用法示例。
在下文中一共展示了Meli.post方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: product_meli_upload_image
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import post [as 别名]
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' }
示例2: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import post [as 别名]
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)
REDIRECT_URI = company.mercadolibre_redirect_uri
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)
if (product.meli_id):
response = meli.get("/items/%s" % product.meli_id, {'access_token':meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title==False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price==False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or '',
"description": product.meli_description or '',
"category_id": product.meli_category.meli_category_id or '0',
"listing_type_id": product.meli_listing_type or '0',
"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
"currency_id": product.meli_currency or '0',
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#print "product.meli_id before setting condigions ]"+product.meli_id+"["
if (len(product.meli_id)==0):
body["condition"] = product.meli_condition;
# print body
assign_img = False and product.meli_id
#publicando imagen cargada en OpenERP
if product.image==None:
return warningobj.info(cr, uid, title='MELI WARNING', message="Debe cargar una imagen de base en el producto.", message_html="" )
elif product.meli_imagen_id==False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if (resim["status"]=="error" or resim["status"]=="warning"):
error_msg = 'MELI: mensaje de error: ', resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
#modificando datos si ya existe el producto en MLA
if (product.meli_id):
body = {
"title": product.meli_title or '',
#"description": product.meli_description or '',
#"category_id": product.meli_category.meli_category_id,
#"listing_type_id": product.meli_listing_type,
#"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
#"currency_id": product.meli_currency,
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
"pictures": [],
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#publicando multiples imagenes
#.........这里部分代码省略.........
示例3: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import post [as 别名]
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)
if product.meli_id:
response = meli.get("/items/%s" % product.meli_id, {"access_token": meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title == False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price == False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or "",
"description": product.meli_description or "",
"category_id": product.meli_category.meli_category_id or "0",
"listing_type_id": product.meli_listing_type or "0",
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
"currency_id": product.meli_currency or "0",
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# print body
assign_img = False and product.meli_id
# publicando imagen cargada en OpenERP
if product.image == None:
return warningobj.info(
cr,
uid,
title="MELI WARNING",
message="Debe cargar una imagen de base en el producto.",
message_html="",
)
elif product.meli_imagen_id == False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if resim["status"] == "error" or resim["status"] == "warning":
error_msg = "MELI: mensaje de error: ", resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
# modificando datos si ya existe el producto en MLA
if product.meli_id:
body = {
"title": product.meli_title or "",
# "description": product.meli_description or '',
# "category_id": product.meli_category.meli_category_id,
# "listing_type_id": product.meli_listing_type,
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
# "currency_id": product.meli_currency,
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
"pictures": [],
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# publicando multiples imagenes
multi_images_ids = {}
#.........这里部分代码省略.........