Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
8 Antwoorden
9567 Weergaven

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 ?

Avatar
Annuleer
Beste antwoord

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);
})
Avatar
Annuleer
Auteur

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 :-)

Beste antwoord

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


Avatar
Annuleer
Beste antwoord

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);
})
Avatar
Annuleer
Auteur

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

Beste antwoord

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); })
Avatar
Annuleer
Auteur

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.

Gerelateerde posts Antwoorden Weergaven Activiteit
2
jan. 23
5958
0
feb. 21
3839
1
aug. 23
411
1
sep. 21
21025
2
apr. 21
4943