تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
8192 أدوات العرض

Hi All

I am attempting to create filters to segment my database. For me it makes sense to use the first letter of Name. i.e. Contacts starting with A, B, C, etc, along with a tag. It seems thought that I get records in multiple filters because it returns contacts that FIRST OR LAST name begin with that letter of the Alphabet. E.g. Doctor Hoffman Will appear in both the D filter and the W filter where I only want him to appear once. I am using this filter for instance:

[['category_id', '=', 'UK Import'], ['name', '=like', 'C']] 


What am I doing wrong? Why is it looking in both the First and Last name and not just the first letter of the name field?


Hope someone can help


Thanks

الصورة الرمزية
إهمال
أفضل إجابة

Hello Dale,

I'm afraid this can't be achieved, all string LIKE/NOT LIKE comparison operators end up matching substrings, either case sensitive or insentitive, please see here:

https://github.com/odoo/odoo/blob/8.0/openerp/osv/expression.py#L1219

Notice how the right leaf (the query parameter) is automatically wrapped in '%' wildcards lines below to end as '%%%s%%' (which evaluates to '%my_search_criteria%').

* https://github.com/odoo/odoo/blob/8.0/openerp/osv/expression.py#L1242

Filters use search by default, which in turn end using domain expressions and hence the above limitation.

Using the exact match operator '=' prevents wrapping the search criteria in wildcards but then any wildcards explicitly provided in the search criteria (like in 'my_search_criteria%') are not taken into account.

Regards.

الصورة الرمزية
إهمال
أفضل إجابة

You should be able to use the filter with a wildcard like the following for starts with / ends with:


# Starts With C
['name', '=like', 'C%']

# Ends With C
['name', '=like', '%C']
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
فبراير 24
1538
0
مايو 17
3333
0
يوليو 25
832
0
يونيو 25
254
1
مايو 25
1563