Add views for WorkedShift
model
This commit is contained in:
parent
2bbd17afa9
commit
4e917169f9
|
@ -72,6 +72,7 @@ def includeme(config):
|
||||||
config.include('tailbone.views.progress')
|
config.include('tailbone.views.progress')
|
||||||
config.include(u'tailbone.views.reportcodes')
|
config.include(u'tailbone.views.reportcodes')
|
||||||
config.include('tailbone.views.roles')
|
config.include('tailbone.views.roles')
|
||||||
|
config.include('tailbone.views.shifts')
|
||||||
config.include('tailbone.views.stores')
|
config.include('tailbone.views.stores')
|
||||||
config.include('tailbone.views.subdepartments')
|
config.include('tailbone.views.subdepartments')
|
||||||
config.include('tailbone.views.taxes')
|
config.include('tailbone.views.taxes')
|
||||||
|
|
88
tailbone/views/shifts.py
Normal file
88
tailbone/views/shifts.py
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# Rattail -- Retail Software Framework
|
||||||
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Rattail.
|
||||||
|
#
|
||||||
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU Affero General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Views for employee shifts
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import humanize
|
||||||
|
|
||||||
|
from rattail.db import model
|
||||||
|
|
||||||
|
import formalchemy
|
||||||
|
|
||||||
|
from tailbone.views import MasterView
|
||||||
|
|
||||||
|
|
||||||
|
class ShiftLengthField(formalchemy.Field):
|
||||||
|
|
||||||
|
def __init__(self, name, **kwargs):
|
||||||
|
kwargs.setdefault('value', self.shift_length)
|
||||||
|
super(ShiftLengthField, self).__init__(name, **kwargs)
|
||||||
|
|
||||||
|
def shift_length(self, shift):
|
||||||
|
if not shift.punch_in or not shift.punch_out:
|
||||||
|
return
|
||||||
|
if shift.punch_out < shift.punch_in:
|
||||||
|
return "??"
|
||||||
|
return humanize.naturaldelta(shift.punch_out - shift.punch_in)
|
||||||
|
|
||||||
|
|
||||||
|
class WorkedShiftsView(MasterView):
|
||||||
|
"""
|
||||||
|
Master view for employee worked shifts.
|
||||||
|
"""
|
||||||
|
model_class = model.WorkedShift
|
||||||
|
url_prefix = '/shifts/worked'
|
||||||
|
|
||||||
|
def configure_grid(self, g):
|
||||||
|
g.default_sortkey = 'punch_in'
|
||||||
|
g.default_sortdir = 'desc'
|
||||||
|
g.append(ShiftLengthField('length'))
|
||||||
|
g.configure(
|
||||||
|
include=[
|
||||||
|
g.employee,
|
||||||
|
g.store,
|
||||||
|
g.punch_in,
|
||||||
|
g.punch_out,
|
||||||
|
g.length,
|
||||||
|
],
|
||||||
|
readonly=True)
|
||||||
|
|
||||||
|
def configure_fieldset(self, fs):
|
||||||
|
fs.append(ShiftLengthField('length'))
|
||||||
|
fs.configure(
|
||||||
|
include=[
|
||||||
|
fs.employee,
|
||||||
|
fs.store,
|
||||||
|
fs.punch_in,
|
||||||
|
fs.punch_out,
|
||||||
|
fs.length,
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def includeme(config):
|
||||||
|
WorkedShiftsView.defaults(config)
|
Loading…
Reference in a new issue