コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
5187 ビュー

I need to add custom filter for a field inside my list view (sale_order_count). How can I add it, I need to filter it like: sale_order_count greater than, less than, etc...

アバター
破棄
著作者

Hello, this blog is to add search filter but I need to add custom filter to search by

最善の回答

Hi Moe,

Please upgrade the module after adding store=True in the field from py side and check.

custom filter conditions are based on the field type. So if you want to see the greater than and less than type of the conditions, then you need to define the fields type as Integer.

Hope it will help you.


アバター
破棄
著作者

It worked, but after I made it as store=True the count of all sale order was reset to 0. Why is this problem?

Hi Moe,
Thanks for giving vote for the answer.
Yes, Now your function will call once you change your function dependent fields and calculate the result . Integer field type has the default value 0.

著作者

Can you give me a glimpse of the code please, I didn't get it so much. You are welcome Malay

Yes sure Moe,
Please try with this

sale_order_count = fields.Integer(compute="_get_sale_order_count", string="Sale Order Count(s)", store=True)

def _get_sale_order_count(self):
for rec in self:
rec.sale_order_count = len(rec.sale_order_ids.ids)

where sale_order_ids is the field inside your model, or search all the sale order ids and add it instead of the len(rec.sale_order_ids.ids)

Please vote up the answer if it helps you.
Thanks

最善の回答

Hi Moe,

In order to add a custom field in filters ,  the field should be a stored field.

If your field sale_order_count is a computed field, you have to store that field using proper dependencies.

After that you can add that field in filters

Hope this will help you 

Thank You

アバター
破棄
著作者

I made the field stored with python code but it is still not showing, any ideas please?

関連投稿 返信 ビュー 活動
1
5月 25
987
2
11月 24
2190
4
2月 24
12344
1
1月 24
1677
0
5月 23
1899