From 73839ea0157b0e558cbbd587c66b05110a39ae58 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 3 Mar 2015 18:16:36 +0100 Subject: [PATCH] when starting a work item stop others that are running; start default date/time is 'now' for start of work --- organize/work.py | 22 +++++++++++++++++++++- organize/work.txt | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/organize/work.py b/organize/work.py index eb49ca9..6692db7 100644 --- a/organize/work.py +++ b/organize/work.py @@ -233,6 +233,9 @@ class WorkItem(Stateful, Track): (action, self.state)) if action in self.specialActions: return self.specialActions[action](self, userName, **kw) + return self.doStandardAction(action, userName, **kw) + + def doStandardAction(self, action, userName, **kw): if self.state == 'new': self.setData(**kw) self.doTransition(action) @@ -283,6 +286,22 @@ class WorkItem(Stateful, Track): delegated.data['target'] = new.name return new + def doStart(self, userName, **kw): + action = 'start' + # stop any running work item of user: + if self.state != 'running': + running = getParent(self).query( + party=userName, state='running') + for wi in running: + wi.doAction('work', userName, + end=(kw.get('start') or getTimeStamp())) + # standard creation of new work item: + if not kw.get('start'): + kw['start'] = getTimeStamp() + kw['end'] = None + kw['duration'] = kw['effort'] = 0 + return self.doStandardAction(action, userName, **kw) + def move(self, userName, **kw): xkw = dict(kw) for k in ('deadline', 'start', 'end'): @@ -319,7 +338,8 @@ class WorkItem(Stateful, Track): item.reindex('state') return new - specialActions = dict(modify=modify, delegate=delegate, move=move, + specialActions = dict(modify=modify, delegate=delegate, + start=doStart, move=move, close=close) def setData(self, ignoreParty=False, **kw): diff --git a/organize/work.txt b/organize/work.txt index ab1cc45..c276fc1 100644 --- a/organize/work.txt +++ b/organize/work.txt @@ -100,7 +100,7 @@ but may also be specified explicitly. >>> wi03 = wi02.doAction('start', 'jim', start=1229958000) >>> wi03 + {'duration': 0, 'start': 1229958000, 'created': ..., 'creator': 'jim'}> Stopping and finishing work --------------------------- @@ -113,7 +113,7 @@ as "running" will be replaced by a new one. >>> wi03 + {'duration': 0, 'start': 1229958000, 'created': ..., 'creator': 'jim'}> >>> wi04