diff --git a/work.py b/work.py
index 6adee043da..dd50d312c4 100644
--- a/work.py
+++ b/work.py
@@ -61,11 +61,7 @@ class Work(ModelSQL, ModelView):
state = fields.Selection([
('opened', 'Opened'),
('done', 'Done'),
- ], 'State',
- states={
- 'invisible': Eval('type') != 'task',
- 'required': Eval('type') == 'task',
- }, select=True, depends=['type'])
+ ], 'State', required=True, select=True)
sequence = fields.Integer('Sequence', required=True)
def default_type(self):
@@ -110,6 +106,19 @@ class Work(ModelSQL, ModelView):
'timesheet work by task/project!'),
]
self._order.insert(0, ('sequence', 'ASC'))
+ self._constraints += [
+ ('check_state',
+ 'A work can not be closed if its children are still opened'),
+ ]
+
+ def check_state(self, ids):
+ for work in self.browse(ids):
+ if ((work.state == 'opened'
+ and (work.parent and work.parent.state == 'done'))
+ or (work.state == 'done'
+ and any(c.state == 'opened' for c in work.children))):
+ return False
+ return True
def get_parent(self, ids, name):
res = dict.fromkeys(ids, None)
diff --git a/work.xml b/work.xml
index 7371f0a43d..60677d3185 100644
--- a/work.xml
+++ b/work.xml
@@ -59,21 +59,6 @@ this repository contains the full copyright notices and license terms. -->
]]>
-
-
- project.work
- tree
-
-
-
-
-
-
-
- ]]>
-
-
project.work
form
@@ -190,7 +175,7 @@ this repository contains the full copyright notices and license terms. -->
-
+