Let config cause time sheet hours to display as HH.HH for some users

default display is still HH:MM however
This commit is contained in:
Lance Edgar 2017-05-15 17:51:24 -05:00
parent d7160a0a38
commit 1dda8a961a

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8; -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
@ -28,12 +28,13 @@ from __future__ import unicode_literals, absolute_import
import datetime import datetime
import six
import sqlalchemy as sa import sqlalchemy as sa
from rattail import enum from rattail import enum
from rattail.db import model, api from rattail.db import model, api
from rattail.time import localtime, make_utc, get_sunday from rattail.time import localtime, make_utc, get_sunday
from rattail.util import pretty_hours from rattail.util import pretty_hours, hours_as_decimal
import formencode as fe import formencode as fe
from pyramid_simpleform import Form from pyramid_simpleform import Form
@ -348,6 +349,13 @@ class TimeSheetView(View):
Fetch all shift data of the given model class (``cls``), according to Fetch all shift data of the given model class (``cls``), according to
the given params. The cached shift data is attached to each employee. the given params. The cached shift data is attached to each employee.
""" """
# TODO: a bit hacky, this? display hours as HH:MM by default, but
# check config in order to display as HH.HH for certain users
hours_style = 'pretty'
if self.request.user:
hours_style = self.rattail_config.get('tailbone', 'hours_style.{}'.format(self.request.user.username),
default='pretty')
shift_type = 'scheduled' if cls is model.ScheduledShift else 'worked' shift_type = 'scheduled' if cls is model.ScheduledShift else 'worked'
min_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[0], datetime.time(0))) min_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[0], datetime.time(0)))
max_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[-1] + datetime.timedelta(days=1), datetime.time(0))) max_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[-1] + datetime.timedelta(days=1), datetime.time(0)))
@ -400,12 +408,18 @@ class TimeSheetView(View):
hours = empday['{}_hours'.format(shift_type)] hours = empday['{}_hours'.format(shift_type)]
if hours: if hours:
empday['{}_hours_display'.format(shift_type)] = pretty_hours(hours) if hours_style == 'pretty':
empday['{}_hours_display'.format(shift_type)] = pretty_hours(hours)
else: # decimal
empday['{}_hours_display'.format(shift_type)] = six.text_type(hours_as_decimal(hours))
employee.weekdays[i].update(empday) employee.weekdays[i].update(empday)
hours = getattr(employee, '{}_hours'.format(shift_type)) hours = getattr(employee, '{}_hours'.format(shift_type))
if hours: if hours:
display = pretty_hours(hours) if hours_style == 'pretty':
display = pretty_hours(hours)
else: # decimal
display = six.text_type(hours_as_decimal(hours))
if hours_incomplete: if hours_incomplete:
display = '{} ?'.format(display) display = '{} ?'.format(display)
setattr(employee, '{}_hours_display'.format(shift_type), display) setattr(employee, '{}_hours_display'.format(shift_type), display)