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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
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
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'}
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
For XML RPC try with search_read. Here is the doc:
https://www.odoo.com/documentation/15.0/developer/misc/api/odoo.html#search-and-read
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jan 21
|
2246 | ||
|
2
Oct 20
|
3915 | ||
|
0
Mar 20
|
18013 | ||
|
2
Dec 23
|
8969 | ||
|
0
Jan 23
|
1238 |
Have a look into:
1- http://learnopenerp.blogspot.com/2018/08/odoo-web-controller.html
2- http://learnopenerp.blogspot.com/2018/06/odoo-get-web-form-template-value-in-controller.html
3- https://learnopenerp.blogspot.com/2019/10/connecting-to-odoo-using-xml-rpc.html