Skip to Content
Menu
This question has been flagged
2 Replies
10912 Rodiniai

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

Portretas
Atmesti
Best Answer
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')
})
Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
0
birž. 21
2365
0
kov. 21
2433
4
vas. 17
21705
1
rugp. 24
4568
1
rugs. 23
2425