Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
10548 Näkymät

So I need to make a Rest service which will call data from an specific model.

In order to do this, I must create a controller.

I'm newbie with Odoo, also with Json, and I can't find anything that could work for this.

Far I have is all I need but in a http request.

class RestService(http.Controller):
    @http.route('/orders/<model("sale.order"):order>', auth='none', website=True)
    def consulta_orden(self , order):
        return request.render('consulta_pedidos.order', {'order': order})
        
        return {'order_id': order_id}

The idea is that when I hace the data loaded, I can render this data in a template. Already did this with an Http request, but I need it with Json. Any tip about how to implement it better.

Avatar
Hylkää
Paras vastaus

Thank you for your answer. It help me a lot. :)

Can you give me a suggestion the link to study Owl and js for Odoo 15?

Avatar
Hylkää
Paras vastaus

Hello Sergio,


To render template with json type controller, you need to pass ajax.jsonRpc through JS and pass your controller url in that for eg.



JS Code:-


ajax.jsonRpc("/orders", 'call', {'order':order}).then(function (modal) {

                $modal.modal('hide') #if you want to hide that modal

            });


Controller code:- 


@http.route(['/orders'], type='json', auth='public',

                methods=['POST'], website=True)

    def consulta_orden(self, order):

        return request.env['ir.ui.view'].render_template(

            'consulta_pedidos.order', {'order': order})


You can also refer this link- https://www.odoo.com/forum/help-1/question/send-json-request-to-controller-the-last-will-render-a-snippet-template-150553


Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 23
3844
1
syysk. 24
1285
1
jouluk. 21
3572
2
jouluk. 23
19339
1
kesäk. 25
2126