Browse Source

base_search_fuzzy: [FIX] Check if functions are already decorated to avoid decorating the function many times whcih leads to recursion errors

pull/462/head
Christoph Giesel 8 years ago
parent
commit
e6c37fb7db
  1. 11
      base_search_fuzzy/models/ir_model.py

11
base_search_fuzzy/models/ir_model.py

@ -43,6 +43,8 @@ def patch_leaf_trgm(method):
eleaf.leaf = (left, operator, right) eleaf.leaf = (left, operator, right)
return method(self, eleaf) return method(self, eleaf)
decorate_leaf_to_sql.__decorated__ = True
return decorate_leaf_to_sql return decorate_leaf_to_sql
@ -52,6 +54,8 @@ def patch_generate_order_by(method):
return ' ORDER BY ' + order_spec return ' ORDER BY ' + order_spec
return method(self, order_spec, query) return method(self, order_spec, query)
decorate_generate_order_by.__decorated__ = True
return decorate_generate_order_by return decorate_generate_order_by
@ -60,11 +64,18 @@ class IrModel(models.Model):
_inherit = 'ir.model' _inherit = 'ir.model'
def _register_hook(self, cr, ids=None): def _register_hook(self, cr, ids=None):
# We have to prevent wrapping the function twice to avoid recursion
# errors
if not hasattr(expression.expression._expression__leaf_to_sql,
'__decorated__'):
expression.expression._expression__leaf_to_sql = patch_leaf_trgm( expression.expression._expression__leaf_to_sql = patch_leaf_trgm(
expression.expression._expression__leaf_to_sql) expression.expression._expression__leaf_to_sql)
if '%' not in expression.TERM_OPERATORS:
expression.TERM_OPERATORS += ('%',) expression.TERM_OPERATORS += ('%',)
if not hasattr(models.BaseModel._generate_order_by,
'__decorated__'):
models.BaseModel._generate_order_by = patch_generate_order_by( models.BaseModel._generate_order_by = patch_generate_order_by(
models.BaseModel._generate_order_by) models.BaseModel._generate_order_by)

Loading…
Cancel
Save