Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
416 Weergaven

I am trying to fetch product images from my Odoo instance using the JSON-RPC method. I am working with the product.image or product.template models, and I want to retrieve the image_1920 field for each product.

product_data = {

"jsonrpc": "2.0",

"method": "call",

"params": {

"service": "object",

"method": "execute_kw",

"args": [

DB, uid, PASSWORD, "product.template", "search_read",

[[]], # Empty list means no filter, fetch all products

{"fields": ["id", "name", "list_price", "image_1920", "description", "categ_id",]}

]

},

"id": 2

}

print("product_data", product_data)



Avatar
Annuleer
Beste antwoord

Hello Uday,

Please have a look following example .

import json
import random
import urllib.request

HOST = 'localhost'
PORT = 8069
DB = 'odoo_v18_all'
USER = 'admin'
PASS = 'admin'

def json_rpc(url, method, params):
data = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": random.randint(0, 1000000000),
}
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
"Content-Type":"application/json",
})
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
if reply.get("error"):
raise Exception(reply["error"])
return reply["result"]

def call(url, service, method, *args):
return json_rpc(url, "call", {"service": service, "method": method, "args": args})

# log in the given database
url = "http://%s:%s/jsonrpc" % (HOST, PORT)
uid = call(url, "common", "login", DB, USER, PASS)

partner_data = call(url, "object", "execute", DB, uid, PASS, 'res.partner', 'search_read', [], ['name', 'country_id', 'comment'])

print("-----partner_data-----",partner_data)

Thanks & Regards,

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209

Email: info@candidroot.com

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
jul. 20
11831
2
mrt. 15
4996
0
mrt. 15
3232
0
feb. 25
698
3
sep. 24
5026