[IMP] resource: improve ugly code in conversion function

bzr revid: rco@openerp.com-20121210090554-fb59bzz5ceogehms
This commit is contained in:
Raphael Collet 2012-12-10 10:05:54 +01:00
parent 7f1d5daf2f
commit 590add54d4
1 changed files with 6 additions and 9 deletions

View File

@ -274,13 +274,10 @@ class resource_calendar_attendance(osv.osv):
}
resource_calendar_attendance()
def convert_timeformat(time_string):
split_list = str(time_string).split('.')
hour_part = split_list[0]
mins_part = split_list[1]
round_mins = int(round(float(mins_part) * 60,-2))
converted_string = hour_part + ':' + str(round_mins)[0:2]
return converted_string
def hours_time_string(hours):
""" convert a number of hours (float) into a string with format '%H:%M' """
minutes = int(round(hours * 60))
return "%02d:%02d" % divmod(minutes, 60)
class resource_resource(osv.osv):
_name = "resource.resource"
@ -390,8 +387,8 @@ class resource_resource(osv.osv):
wk_days[week['dayofweek']] = week_days[week['dayofweek']]
else:
raise osv.except_osv(_('Configuration Error!'),_('Make sure the Working time has been configured with proper week days!'))
hour_from_str = convert_timeformat(week['hour_from'])
hour_to_str = convert_timeformat(week['hour_to'])
hour_from_str = hours_time_string(week['hour_from'])
hour_to_str = hours_time_string(week['hour_to'])
res_str = hour_from_str + '-' + hour_to_str
wktime_list.append((day, res_str))
# Convert into format like [('mon', '8:00-12:00', '13:00-18:00')]