|
|
@ -1,11 +1,12 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Eficent Business and IT Consulting Services S.L. |
|
|
|
# © 2016 Serpent Consulting Services Pvt. Ltd. |
|
|
|
# Copyright 2017 LasLabs Inc. |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
|
|
import logging |
|
|
|
|
|
|
|
from openerp import models, api |
|
|
|
from openerp.osv import expression |
|
|
|
from odoo import _, api, models |
|
|
|
from odoo.osv import expression |
|
|
|
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
@ -19,23 +20,28 @@ def patch_leaf_trgm(method): |
|
|
|
table_alias = '"%s"' % (eleaf.generate_alias()) |
|
|
|
|
|
|
|
if operator == '%': |
|
|
|
|
|
|
|
sql_operator = '%%' |
|
|
|
params = [] |
|
|
|
|
|
|
|
if left in model._columns: |
|
|
|
formats = model._columns[left]._symbol_set[0] |
|
|
|
if left in model._fields: |
|
|
|
column = '%s.%s' % (table_alias, expression._quote(left)) |
|
|
|
query = '(%s %s %s)' % (column, sql_operator, formats) |
|
|
|
elif left in expression.MAGIC_COLUMNS: |
|
|
|
query = '(%s %s %s)' % ( |
|
|
|
column, |
|
|
|
sql_operator, |
|
|
|
model._fields[left].column_format, |
|
|
|
) |
|
|
|
elif left in models.MAGIC_COLUMNS: |
|
|
|
query = "(%s.\"%s\" %s %%s)" % ( |
|
|
|
table_alias, left, sql_operator) |
|
|
|
params = right |
|
|
|
else: # Must not happen |
|
|
|
raise ValueError( |
|
|
|
"Invalid field %r in domain term %r" % (left, leaf)) |
|
|
|
raise ValueError(_( |
|
|
|
"Invalid field %r in domain term %r" % (left, leaf) |
|
|
|
)) |
|
|
|
|
|
|
|
if left in model._columns: |
|
|
|
params = model._columns[left]._symbol_set[1](right) |
|
|
|
if left in model._fields: |
|
|
|
params = str(right) |
|
|
|
|
|
|
|
if isinstance(params, basestring): |
|
|
|
params = [params] |
|
|
@ -67,7 +73,8 @@ class IrModel(models.Model): |
|
|
|
|
|
|
|
_inherit = 'ir.model' |
|
|
|
|
|
|
|
def _register_hook(self, cr, ids=None): |
|
|
|
@api.model_cr |
|
|
|
def _register_hook(self): |
|
|
|
# We have to prevent wrapping the function twice to avoid recursion |
|
|
|
# errors |
|
|
|
if not hasattr(expression.expression._expression__leaf_to_sql, |
|
|
@ -82,4 +89,4 @@ class IrModel(models.Model): |
|
|
|
'__decorated__'): |
|
|
|
models.BaseModel._generate_order_by = patch_generate_order_by( |
|
|
|
models.BaseModel._generate_order_by) |
|
|
|
return super(IrModel, self)._register_hook(cr) |
|
|
|
return super(IrModel, self)._register_hook() |