diff --git a/trytond/trytond/model/fields/numeric.py b/trytond/trytond/model/fields/numeric.py index 536c2d800a..13b3404852 100644 --- a/trytond/trytond/model/fields/numeric.py +++ b/trytond/trytond/model/fields/numeric.py @@ -1,19 +1,12 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from decimal import Decimal -from sql import Cast, Literal, Select, CombiningQuery, As +from sql import Cast, Literal, Select, CombiningQuery 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``). @@ -22,18 +15,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 3a87c53f96..957118c1ad 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -1351,6 +1351,11 @@ class ModelSQL(ModelStorage): columns += [Extract('EPOCH', Coalesce(main_table.write_date, main_table.create_date) ).cast(sql_type).as_('_timestamp')] + 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, order_by=order_by, limit=limit, offset=offset) if query: