Skip to Content
Menu
This question has been flagged
2 Replies
4041 Views

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...

Avatar
Discard
Author

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

Best Answer

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.


Avatar
Discard
Author

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.

Author

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

Best Answer

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

Avatar
Discard
Author

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

Related Posts Replies Views Activity
2
Nov 24
476
4
Feb 24
10164
1
Jan 24
369
0
May 23
831
4
Apr 23
38315