跳至內容
選單
此問題已被標幟
3 回覆
16976 瀏覽次數

Odoo version 11.0

Currently, i got product by filter like,

lafilter[0] = new object[3] { "type", "=", "product" };

- and also i want to add one more filter for get unique record, like "distinct by Id" 

any idea about "distinct" record ?

Thanks 

頭像
捨棄
最佳答案

Hi, 

You can group by that field by calling read_group function, for example:

result = self.env['yourmodel'].read_group([ ("type", "=", "product") ], fields=['Id'], groupby=['Id'])


PS: if you liked the answer - please upvote it :)

頭像
捨棄

Awesome!!!

最佳答案

if you are working in JavaScript here is the rpc query


                    rpc.query({
model: 'sale.report',
method: 'read_group',
fields: ['price_subtotal:sum'],
kwargs: {groupby: 'date:year'},
lazy: false,
}).then(function (result) {
console.log(result)
});

頭像
捨棄
最佳答案

Hello

I used read_group like this.

But without orderby=False then 'ORDER BY "id" is ambiguous' or

with orderby=['id'] then 'TypeError: expected string or bytes-like object'

How can I use it?

頭像
捨棄

I changed with orderby='name' is working

相關帖文 回覆 瀏覽次數 活動
1
1月 19
5347
0
11月 18
4088
1
11月 22
3241
2
8月 22
7586
1
1月 25
9282