Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
add matches method to ClockPunch
Browse files Browse the repository at this point in the history
  • Loading branch information
snarlygoster committed May 10, 2012
1 parent e666591 commit 072a1fc
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions timeclock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@ class ClockPunch(models.Model):
activity = models.ForeignKey(Activity)
worker = models.ForeignKey(Worker)

def matches(self, *args, **kwargs):
break_event = Activity.objects.get(ticket="Break")
open_event = Activity.objects.get(ticket="Open Shop")
close_event = Activity.objects.get(ticket="Close Shop")

dates = ClockPunch.objects.dates('timestamp','day')
punches = ClockPunch.objects.all().order_by('timestamp')

scoreboard = {}



for punch in punches:
if punch.activity == open_event:
pass
elif punch.activity == close_event:
self.close_all_sessions(punch.timestamp)
elif punch.activity == break_event:
if punch.worker not in self.scoreboard:
pass
else:
wp = WorkPeriod(start_punch = self.scoreboard[punch.worker]['start'], end_punch=punch)
wp.save()
del self.scoreboard[punch.worker]
elif punch.worker not in self.scoreboard:
self.scoreboard[punch.worker] = {"start" : punch}
else:
wp = WorkPeriod(start_punch = self.scoreboard[punch.worker]['start'], end_punch=punch)
wp.save()

self.scoreboard[punch.worker] = {"start" : punch}

class Meta:
ordering = ['-timestamp',]

Expand Down Expand Up @@ -161,6 +193,8 @@ def _get_duration(self):
end_time = property(_get_end_time)
duration = property(_get_duration)

## TODO: add save method to set start-punch as logged

class Meta:
pass
#ordering = ['start_time',]
Expand Down

0 comments on commit 072a1fc

Please sign in to comment.