Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
8 Odpowiedzi
9568 Widoki

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 ?

Awatar
Odrzuć
Najlepsza odpowiedź

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);
})
Awatar
Odrzuć
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 :-)

Najlepsza odpowiedź

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


Awatar
Odrzuć
Najlepsza odpowiedź

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);
})
Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

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); })
Awatar
Odrzuć
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.

Powiązane posty Odpowiedzi Widoki Czynność
2
sty 23
5958
0
lut 21
3839
1
sie 23
411
1
wrz 21
21025
2
kwi 21
4943