Skip to Content
Menu
This question has been flagged
1 Reply
4249 Views

Hey can anyone tell how to make a get request to get all the values in the One2many field 'order_lines' of sale module. Same question for making a POST request too.

Thanks in advance

Avatar
Discard
Best Answer

You can make a request to sale.order.line model directly. By default you can do that using xmlrpc. Additionally I recommend to use wrappers like odoorpc, for example.

If you want to make a get request you should create a custom controller to access the data, designing the idea first. There are some examples of the design here: 

https://app.apiary.io/iwodoo

Avatar
Discard
Author

Hey thanks for your reply, i have made the controller its working for simple fields can you share your controller chunk how you storing it?

Here you have an example for the iwodoo /partner/read

The security is made with a token. Try a hardcoded token for this example. This works for any kind of field. You can also use the read() method over the object to bring a complete dictionary, or you can choose as here, the fields you want.

For your case, the filter could be something like search([('move_id', '=', record_id_you_are_looking for)])

@http.route(['/partner/read'], type='json', auth="public", website=True, methods=['GET', 'POST'], csrf=False)

def partner_read(self, vat):

if not self.check_security():

return {'error': 'not autorized'}

partner_obj = http.request.env['res.partner'].sudo()

try:

partner_id = partner_obj.search([('vat', '=', 'CL'+vat.replace('.', '').replace('-', ''))])[0]

return {

'contact_address': partner_id.contact_address,

'parent_name': partner_id.parent_name,

'display_name': partner_id.display_name,

'opt_out': partner_id.opt_out,

'title': partner_id.title.name,

'commercial_company_name': partner_id.commercial_company_name,

'employee': partner_id.employee,

'supplier_invoice_count': partner_id.supplier_invoice_count,

'property_supplier_payment_term_id': partner_id.property_supplier_payment_term_id.name,

'customer': partner_id.customer,

'fax': partner_id.fax,

'name': partner_id.name,

'debit_limit': partner_id.debit_limit,

'total_invoiced': partner_id.total_invoiced,

'notify_email': partner_id.notify_email,

'street': partner_id.street,

}

except IndexError:

return {'error': 'No records found'}

Author

Hey daniel i have done this bit with the sale order. the issue i am facing is the dictionary which i had to make for sale.order.line or for one2many field order_line. Thanks for the effort man

please give me exmple one2many with xml rpc and thank you

In the previous code, simply try to do:

partner_id.read()

this will bring a huge dictionary with almost everything you need. Even, try to apply the .read() to those one2many fields

Related Posts Replies Views Activity
1
Jan 21
2246
2
Oct 20
3915
0
Mar 20
18013
2
Dec 23
8969
0
Jan 23
1238