Add initial Time Sheet view
Hardly complete at this point, but proves the concept.
This commit is contained in:
parent
fb25f6917e
commit
22e4d38d58
73
tailbone/templates/timesheet/index.mako
Normal file
73
tailbone/templates/timesheet/index.mako
Normal file
|
@ -0,0 +1,73 @@
|
|||
## -*- coding: utf-8 -*-
|
||||
<%inherit file="/base.mako" />
|
||||
|
||||
<%def name="title()">Time Sheet</%def>
|
||||
|
||||
<%def name="head_tags()">
|
||||
${parent.head_tags()}
|
||||
<style type="text/css">
|
||||
.timesheet {
|
||||
border-bottom: 1px solid black;
|
||||
border-right: 1px solid black;
|
||||
width: 100%;
|
||||
}
|
||||
.timesheet thead th {
|
||||
width: 12.5%;
|
||||
}
|
||||
.timesheet thead th,
|
||||
.timesheet tbody td {
|
||||
border-left: 1px solid black;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
.timesheet tbody td {
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
.timesheet tbody p.shift {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</%def>
|
||||
|
||||
<div class="field-wrapper employee">
|
||||
<label>Employee</label>
|
||||
<div class="field">
|
||||
${employee}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Week of</label>
|
||||
<div class="field">
|
||||
${week_of}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="timesheet">
|
||||
<thead>
|
||||
<tr>
|
||||
% for day in weekdays:
|
||||
<th>${day.strftime('%A')}<br />${day.strftime('%b %d')}</th>
|
||||
% endfor
|
||||
<th>Total<br />Hours</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
% for day in employee.weekdays:
|
||||
<td>
|
||||
% for shift in day['shifts']:
|
||||
<p class="shift">${shift.get_display(request.rattail_config)}</p>
|
||||
% endfor
|
||||
</td>
|
||||
% endfor
|
||||
<td>${employee.hours_display}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
% for day in employee.weekdays:
|
||||
<td>${day['hours_display']}</td>
|
||||
% endfor
|
||||
<td>${employee.hours_display}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
111
tailbone/views/timesheet.py
Normal file
111
tailbone/views/timesheet.py
Normal file
|
@ -0,0 +1,111 @@
|
|||
# -*- 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 time sheets
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.time import localtime, get_sunday
|
||||
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import View
|
||||
|
||||
|
||||
class TimeSheetView(View):
|
||||
"""
|
||||
Simple view for current user's time sheet.
|
||||
"""
|
||||
|
||||
def __call__(self):
|
||||
employee = self.request.user.employee
|
||||
assert employee
|
||||
today = localtime(self.rattail_config).date()
|
||||
sunday = get_sunday(today)
|
||||
|
||||
weekdays = [sunday]
|
||||
for i in range(1, 7):
|
||||
weekdays.append(sunday + datetime.timedelta(days=i))
|
||||
|
||||
saturday = weekdays[-1]
|
||||
if saturday.year == sunday.year:
|
||||
week_of = '{} - {}'.format(sunday.strftime('%a %b %d'), saturday.strftime('%a %b %d, %Y'))
|
||||
else:
|
||||
week_of = '{} - {}'.format(sunday.strftime('%a %b %d, Y'), saturday.strftime('%a %b %d, %Y'))
|
||||
|
||||
min_punch = localtime(self.rattail_config, datetime.datetime.combine(sunday, datetime.time(0)))
|
||||
max_punch = localtime(self.rattail_config, datetime.datetime.combine(saturday + datetime.timedelta(days=1), datetime.time(0)))
|
||||
shifts = Session.query(model.WorkedShift)\
|
||||
.filter(model.WorkedShift.employee == employee)\
|
||||
.filter(model.WorkedShift.punch_in >= min_punch)\
|
||||
.filter(model.WorkedShift.punch_in < max_punch)\
|
||||
.order_by(model.WorkedShift.punch_in, model.WorkedShift.punch_out)\
|
||||
.all()
|
||||
|
||||
shifts_copy = list(shifts)
|
||||
employee.weekdays = []
|
||||
employee.hours = datetime.timedelta(0)
|
||||
for day in weekdays:
|
||||
empday = {'shifts': [], 'hours': datetime.timedelta(0)}
|
||||
|
||||
while shifts_copy:
|
||||
shift = shifts_copy[0]
|
||||
if shift.get_date(self.rattail_config) == day:
|
||||
empday['shifts'].append(shift)
|
||||
empday['hours'] += shift.length
|
||||
employee.hours += shift.length
|
||||
del shifts_copy[0]
|
||||
else:
|
||||
break
|
||||
|
||||
empday['hours_display'] = ''
|
||||
if empday['hours']:
|
||||
minutes = (empday['hours'].days * 1440) + (empday['hours'].seconds / 60)
|
||||
empday['hours_display'] = '{}:{:02d}'.format(minutes // 60, minutes % 60)
|
||||
employee.weekdays.append(empday)
|
||||
|
||||
employee.hours_display = ''
|
||||
if employee.hours:
|
||||
minutes = (employee.hours.days * 1440) + (employee.hours.seconds / 60)
|
||||
employee.hours_display = '{}:{:02d}'.format(minutes // 60, minutes % 60)
|
||||
|
||||
return {
|
||||
'employee': employee,
|
||||
'week_of': week_of,
|
||||
'sunday': sunday,
|
||||
'weekdays': weekdays,
|
||||
'shifts': shifts,
|
||||
}
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
||||
# current user's time sheet
|
||||
config.add_route('timesheet', '/timesheet/')
|
||||
config.add_view(TimeSheetView, route_name='timesheet',
|
||||
renderer='/timesheet/index.mako',
|
||||
permission='timesheet.view')
|
||||
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
|
Loading…
Reference in a new issue