Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10933 Lượt xem

i'am trying to integare odoo with  imdb.com which have it's own APIs on omdbapi.com 

i  need to fictch movies as products on odoo then make apurchase orders on it the site says\for searching i should use this api

\\\http://www.omdbapi.com/?apikey="i must but my key here"&t="the movie Name i want to search"

i'am tried to do it by this way

class Api(http.Controller):
@http.route('/api', auth='public', methods=["get"])
def index(self, **kw):
    url = 'http://www.omdbapi.com/?apikey=15439843&t=hello'
    r = requests.get(url)
    return r.text

it return a json with data of the movie hello but here it's a static parameter how can i make it dynamic and get the movie name from field or data input then i need to get the json parameters on method create of product.tempalte

add_product = http.request.env['product.template'].sudo().create({
         'name': "movie name form json"
         })
return add_product

any help well be very appreciated

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
there is no need to create controller. just override create method of your model like

def create(self, vals):
name = vals.get('name')
if name:
url = 'http://www.omdbapi.com/?apikey=15439843&t=%s' % name
response = requests.get(url)
movies = response.json()
# formate movi list
self.env['product.template'].sudo().create({
'director': movies.get('Director')
})
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 6 21
2392
0
thg 3 21
2454
4
thg 2 17
21726
1
thg 8 24
4582
1
thg 9 23
2448