[FIX] base: partner search no alnum->no VAT match

When we search a partner, there is a system that show partner who match
exactly the searched term with non-alphanumeric character removed.

But since a6e1eb9f0a there is an issue that wrong partner match if:

- they have an empty string as VAT in the database (odd but can happen)
- if the searched term only contains non-alphanumberic characters

eg. i search 'é' -> all partner with empty string vat are found since
    the empty search '' matches empty VAT ''

With this changeset, if there is no alphanumeric character we will check
depending on the operator `vat=NULL`, `vat like NULL`, `vat ilike NULL`
that all will not match any result (and in the query plan does not take
time).

opw-1929563
closes #30732
This commit is contained in:
Nicolas Lempereur
2019-02-01 08:06:16 +00:00
parent 90b6cbde09
commit 3076d7e464
+1 -1
View File
@@ -712,7 +712,7 @@ class Partner(models.Model):
vat=unaccent('res_partner.vat'),)
where_clause_params += [search_name]*3 # for email / display_name, reference
where_clause_params += [re.sub('[^a-zA-Z0-9]+', '', search_name)] # for vat
where_clause_params += [re.sub('[^a-zA-Z0-9]+', '', search_name) or None] # for vat
where_clause_params += [search_name] # for order by
if limit:
query += ' limit %s'