[FIX] crm: incorrect field name as expression source

PR #105873 added computed indexes on the `mobile` and `phone` commits
for the benefit of `phone_mobile_search`, however it created both
indexes to work on the `phone` field as source, rather than whichever
field they were named after and partial for. As a result, the index
has no effect when searching on `mobile`.

closes odoo/odoo#135878

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
Xavier Morel
2023-09-21 08:59:47 +00:00
parent 1e6baf4909
commit 62d3e1a1a3
+1 -1
View File
@@ -743,7 +743,7 @@ class Lead(models.Model):
index_name = f'crm_lead_{field_name}_partial_tgm'
if tools.index_exists(self._cr, index_name):
continue
regex_expression = "regexp_replace((phone::text), %s::text, ''::text, 'g'::text)"
regex_expression = f"regexp_replace(({field_name}::text), %s::text, ''::text, 'g'::text)"
self._cr.execute(
f'CREATE INDEX "{index_name}" ON "{self._table}" ({regex_expression}) WHERE {field_name} IS NOT NULL',
(phone_pattern,)