diff --git a/trytond/trytond/model/fields/numeric.py b/trytond/trytond/model/fields/numeric.py index 336b12499f..da32460301 100644 --- a/trytond/trytond/model/fields/numeric.py +++ b/trytond/trytond/model/fields/numeric.py @@ -2,20 +2,13 @@ # this repository contains the full copyright notices and license terms. from decimal import Decimal -from sql import As, Cast, CombiningQuery, Literal, Select +from sql import Cast, CombiningQuery, Literal, Select from trytond import backend from .float import Float -class SQLite_Cast(Cast): - - def as_(self, output_name): - # Use PARSE_COLNAMES instead of CAST for final column - return As(self.expression, '%s [NUMERIC]' % output_name) - - class Numeric(Float): ''' Define a numeric field (``decimal``). @@ -24,18 +17,16 @@ class Numeric(Float): _sql_type = 'NUMERIC' _py_type = Decimal - def sql_column(self, table): - column = super(Numeric, self).sql_column(table) - db_type = backend.name - if db_type == 'sqlite': + def _domain_column(self, operator, column): + column = super()._domain_column(operator, column) + if backend.name == 'sqlite': # Must be casted as Decimal is stored as bytes - column = SQLite_Cast(column, self.sql_type().base) + column = Cast(column, self.sql_type().base) return column def _domain_value(self, operator, value): value = super(Numeric, self)._domain_value(operator, value) - db_type = backend.name - if db_type == 'sqlite': + if backend.name == 'sqlite': if isinstance(value, (Select, CombiningQuery)): return value # Must be casted as Decimal is adapted to bytes diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 804f8fda4a..b633626618 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -1825,6 +1825,11 @@ class ModelSQL(ModelStorage): # compute it here because __search_order might modify tables table = convert_from(None, tables) columns = cls.__searched_columns(main_table, eager=not query) + if backend.name == 'sqlite': + for column in columns: + field = cls._fields.get(column.output_name) + if field: + column.output_name += ' [%s]' % field.sql_type().base select = table.select( *columns, where=expression, limit=limit, offset=offset, order_by=order_by)