Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
8 Răspunsuri
9566 Vizualizări

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 ?

Imagine profil
Abandonează
Cel mai bun răspuns

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);
})
Imagine profil
Abandonează
Autor

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

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

Cel mai bun răspuns

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


Imagine profil
Abandonează
Cel mai bun răspuns

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);
})
Imagine profil
Abandonează
Autor

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

Cel mai bun răspuns

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); })
Imagine profil
Abandonează
Autor

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.

Related Posts Răspunsuri Vizualizări Activitate
2
ian. 23
5958
0
feb. 21
3839
1
aug. 23
411
1
sept. 21
21025
2
apr. 21
4943