Fix float_time widget to allow None as value
issue2520
This commit is contained in:
1 parent
5fc2e616f4
commit
ae113f5ebe
3 files changed
+12
-10
No files matched your search
@@ -1330,10 +1330,12 @@ FLOAT_TIME_SEPS = {
|
||||
}
|
||||
|
||||
|
||||
def text_to_float_time(text, conv=None):
|
||||
def text_to_float_time(text, conv=None, digit=2):
|
||||
if not text:
|
||||
return None
|
||||
try:
|
||||
try:
|
||||
return locale.atof(text)
|
||||
return round(locale.atof(text), digit)
|
||||
except ValueError:
|
||||
pass
|
||||
if conv:
|
||||
@@ -1368,12 +1370,14 @@ def text_to_float_time(text, conv=None):
|
||||
break
|
||||
if text.startswith('-'):
|
||||
value *= -1
|
||||
return value
|
||||
return round(value, digit)
|
||||
except ValueError:
|
||||
return 0.0
|
||||
|
||||
|
||||
def float_time_to_text(val, conv=None):
|
||||
if val is None:
|
||||
return ''
|
||||
if conv:
|
||||
tmp_conv = FLOAT_TIME_CONV.copy()
|
||||
tmp_conv.update(conv)
|
||||
@@ -1404,7 +1408,7 @@ def float_time_to_text(val, conv=None):
|
||||
value += ' ' + locale.format('%d', weeks, True) + FLOAT_TIME_SEPS['w']
|
||||
if days:
|
||||
value += ' ' + locale.format('%d', days, True) + FLOAT_TIME_SEPS['d']
|
||||
if hours or mins:
|
||||
if hours or mins or not value:
|
||||
value += ' %02d:%02d' % (hours, mins)
|
||||
value = value.strip()
|
||||
return value
|
||||
|
||||
@@ -36,22 +36,20 @@ class FloatTime(WidgetInterface):
|
||||
def modified(self):
|
||||
if self.record and self.field:
|
||||
value = self.entry.get_text()
|
||||
return common.float_time_to_text( self.field.get(self.record),
|
||||
return common.float_time_to_text(self.field.get(self.record),
|
||||
self.conv) != value
|
||||
return False
|
||||
|
||||
def set_value(self, record, field):
|
||||
value = self.entry.get_text()
|
||||
if not value:
|
||||
return field.set_client(record, 0.0)
|
||||
digits = field.digits(record)
|
||||
return field.set_client(record,
|
||||
round(common.text_to_float_time(value, self.conv), digits[1]))
|
||||
common.text_to_float_time(value, self.conv, digits[1]))
|
||||
|
||||
def display(self, record, field):
|
||||
super(FloatTime, self).display(record, field)
|
||||
if not field:
|
||||
self.entry.set_text('00:00')
|
||||
self.entry.set_text('')
|
||||
return False
|
||||
val = field.get(record)
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ class FloatTime(Char):
|
||||
field = record[self.field_name]
|
||||
digits = field.digits(record)
|
||||
field.set_client(record,
|
||||
round(common.text_to_float_time(text, self.conv), digits[1]))
|
||||
common.text_to_float_time(text, self.conv, digits[1]))
|
||||
if callback:
|
||||
callback()
|
||||
|
||||
|
||||
Reference in new issue
Block a user