콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
396 화면

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)



아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
3
7월 20
11804
2
3월 15
4975
0
3월 15
3205
0
2월 25
685
3
9월 24
4943