Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

"WHERE" in RPC Web module request (6.1)

By
Ikss
on 3/25/13, 8:46 AM 2,561 views

Hi,

I'm trying to make a RPC request. I want to select records where name="Smith". I'm using OpenERP 6.1, and I'm building a web module. This code is in a custom widget :

 this.rpc('/web/dataset/search_read', {
            model: 'people',
            fields: field || false,
            domain: this.view.domain,
            context: { 'name' : 'Smith'},
            offset: 0,
            limit: false
        }).pipe(function (result) {
            self.ids = result.ids;
            self._length = result.length;
            console.log(result.records);
})

I tried to use Context parameters, but it doesn't work, I keep getting all the records in the table. How to do please ?

1

IBS

--IBS--
1302
| 4 5 8
Tétouan, Morocco
--IBS--

For more informations about IBS, please visit our website at www.ibs-na.com.

For a specific questions, collaboration or help, please send us an email to support@ibs-na.com

IBS
On 3/25/13, 9:50 AM

You have to add a filter to the domain, like this:

this.rpc('/web/dataset/search_read', {
            model: 'people',
            fields: field || false,
            domain: [ ['name', '=', 'Smith'] ],
            offset: 0,
            limit: false
        }).pipe(function (result) {
            self.ids = result.ids;
            self._length = result.length;
            console.log(result.records);
})

You rock, that's exactly what I need. Thank you very much :)

Ikss
on 3/25/13, 10:01 AM

You are welcome, please don't forget to mark the answer as correct :-)

IBS
on 3/25/13, 2:46 PM
0
xiaolong97427
On 4/19/16, 11:11 AM

How can I find the description of all these RPC method ? The below links didn't give all option of the search_read

 method, nor the url to call: /web/dataset/search_read


https://www.odoo.com/documentation/9.0/api_integration.html

http://odoo-new-api-guide-line.readthedocs.org/en/latest/environment.html#search-read


0

saad

--saad--
1008
| 5 4 8
Casablanca, Morocco
--saad--
saad
On 3/25/13, 9:15 AM

I think you should remove { 'name' : 'Smith'} to the fields parameters

this.rpc('/web/dataset/search_read', {
            model: 'people',
            fields: { 'name' : 'Smith'},

        }).pipe(function (result) {
            self.ids = result.ids;
            self._length = result.length;
            console.log(result.records);
})

It still returns all records of the table, not just Smith, but I have only the field name in the result.

Ikss
on 3/25/13, 9:23 AM
0

IBS

--IBS--
1302
| 4 5 8
Tétouan, Morocco
--IBS--

For more informations about IBS, please visit our website at www.ibs-na.com.

For a specific questions, collaboration or help, please send us an email to support@ibs-na.com

IBS
On 3/25/13, 9:06 AM

Try it this way:

this.rpc('/web/dataset/search_read', {
            model: 'people',
            fields: field || false,
            domain: this.view.domain,
            name: 'Smith',
            offset: 0,
            limit: false
        }).pipe(function (result) {
            self.ids = result.ids;
            self._length = result.length;
            console.log(result.records); })

Thanks for trying to help. However, It doesn't work : TypeError: search_read() got an unexpected keyword argument 'name'

That's why i was trying with domain and context, but I'm not sure of what they do.

Ikss
on 3/25/13, 9:15 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/25/13, 8:46 AM
Seen: 2561 times
Last updated: 4/19/16, 11:11 AM