Skip to content Skip to sidebar Skip to footer

How To Get Specific Record In Json Controller In Odoo 12

My question says it all. I already did a controller to search all records from specific model. Now I want to search just one record (by its id) from the same model. My controller f

Solution 1:

Firstly, change your controller route like so:

@http.route(['/get_sales', '/get_sales/<int:order_id>'], type='json', auth='user')

By doing that you now have the option to call your route with or without an order_id.

Secondly, change your method like so:

def get_sales(self, order_id=None):

Now you can add some logic into your method:

if order_id:
    domain = [('id', '=', order_id)]
else:
    domain = []
sales_rec = request.env['sale.order'].search(domain)

Solution 2:

sale_rec = request.env['sale.order'].search([('id','=',YOURID)])

or

sale_rec = request.env['sale.order'].browse(YOURID)

Both return the selected object


Post a Comment for "How To Get Specific Record In Json Controller In Odoo 12"