Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
8 ตอบกลับ
9574 มุมมอง

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 ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

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

คำตอบที่ดีที่สุด

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


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

คำตอบที่ดีที่สุด

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ม.ค. 23
5967
0
ก.พ. 21
3842
1
ส.ค. 23
411
1
ก.ย. 21
21034
2
เม.ย. 21
4950