Skip to Content
Menu
This question has been flagged
3 Replies
10974 Views

I use a simple JSONRPC query, to search_read all sale orders created with partners with country = 76 (France)

{"jsonrpc":"2.0","method":"call","params":{"service":"object","method":"execute","args":["admin3",1,"admin","sale.order","search_read",[["partner_id.country_id","=",76]],["name"]]},"id":"1"}

 

It's working fine.

My question is : if it's possible to search on a joined field (partner_id.country_id in this case), why it seems impossible to display the content of this joined field, in the query result ?

 

{"jsonrpc":"2.0","method":"call","params":{"service":"object","method":"execute","args":["admin3",1,"admin","sale.order","search_read",[["partner_id.country_id","=",76]],["name","partner_id.country_id"]]},"id":"1"}

 

Gives only the "name" of sale orders. Syntax problem ? Or real technical impossibility ? And if so, what would be the reason ?

Avatar
Discard
Best Answer

https://www.odoo.com/documentation/12.0/webservices/odoo.html

"sale.order" models field name defined in fields values in dictionary. If country_id field not available in the sale.order, In that case odoo custom module inherit sale.order and add related field country_id add store= True parameter it will save country_id data in database.

Domain can check res_partner.country_id, but cannot display res_partner field with dot notation. country_id field should be available in sale.order table, then only display. In that case create related field and display.

Example,

class SalesOrdercountry(models.Model):
_inherit = 'sale.order'

country_id = fields.Many2one('res.country', related='partner_id.country_id', string='Country', store=True)
models.execute_kw(db, uid, password, 'sale.order', 'search_read', [[['partner_id.country_id.id','=',79]]], {'fields': ['name', 'country_id']})
Avatar
Discard
Best Answer

First try

{"jsonrpc":"2.0","method":"call","params":{"service":"object","method":"execute","args":["admin3",1,"admin","sale.order","search_read",[["partner_id.country_id","=",76]], {}},"id":"1

You should get all data. 


Then

{"jsonrpc":"2.0","method":"call","params":{"service":"object","method":"execute","args":["admin3",1,"admin","sale.order","search_read",[["partner_id.country_id","=",76]], { "name" : [],"partner_id.country_id":[]},"id":"1

You should get name and partners country data.

Sorry if the code wrong I edit it from my phone. It work something like that

And thank you btw , your code example make my json works 

Avatar
Discard
Author Best Answer

I looked at the server with the SQL debug mode... and it's not really pretty.

I thought that the ORM was capable of doing JOIN queries...

With my example, actually, the system performs first a SELECT on res.partner to retrieve the IDs of all the partners who have country = 76... In my case : a few thousands of IDs... !

And then, another SELECT... on sale.order to find SO with... partner_id among the previous list of IDs.

No JOIN queries, brutal force instead. And therefore, no way to display columns from res.partners with a simple search_read query on sale.order.

If I understand the ORM's logic, I would need to inherit the model sale.order, add a few columns (partner.id.country, or phone, or whatever else) linked to the res.partner model, I would need to work on "on change" stuff, and fix some list views.

Lot of work, isn't it?

Or do I miss something obvious ?

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 15
2803
2
Mar 15
4538
3
Sep 24
2405
1
Feb 24
632
2
Dec 22
3768