From e7b3c88c7365fbfa2ec3058629b80fbea75d4b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 16 Jan 2011 22:18:27 +0100 Subject: [PATCH] Return Decimal value for numeric search for issue1805 (transplanted from 6dcc64647e04d84180e7db50e4e86f99335c3fb8) --- .../window/view_form/widget_search/float.py | 21 +++++++++++++++++++ .../window/view_form/widget_search/form.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tryton/gui/window/view_form/widget_search/float.py b/tryton/gui/window/view_form/widget_search/float.py index 73144a8885..ee6004ddfb 100644 --- a/tryton/gui/window/view_form/widget_search/float.py +++ b/tryton/gui/window/view_form/widget_search/float.py @@ -1,6 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. import locale +from decimal import Decimal from integer import Integer import gettext @@ -64,3 +65,23 @@ class Float(Integer): widget.stop_emission('insert-text') except: widget.stop_emission('insert-text') + + +class Numeric(Float): + + def _value_get(self): + try: + value1 = Decimal(str(locale.atof(self.entry1.get_text()))) + except Exception: + value1 = False + try: + value2 = Decimal(str(locale.atof(self.entry2.get_text()))) + except Exception: + value2 = False + res = self._get_clause(value1, value2) + return res + + def _value_set(self, value): + super(Numeric, self)._value_set(value) + + value = property(_value_get, _value_set) diff --git a/tryton/gui/window/view_form/widget_search/form.py b/tryton/gui/window/view_form/widget_search/form.py index 4651dc9e44..7d4185eeb9 100644 --- a/tryton/gui/window/view_form/widget_search/form.py +++ b/tryton/gui/window/view_form/widget_search/form.py @@ -284,7 +284,7 @@ WIDGETS_TYPE = { 'date': (calendar.Calendar, 2), 'datetime': (calendar.Calendar, 2), 'float': (float.Float, 2), - 'numeric': (float.Float, 2), + 'numeric': (float.Numeric, 2), 'integer': (integer.Integer, 2), 'biginteger': (integer.Integer, 2), 'selection': (selection.Selection, 2),