diff --git a/CHANGELOG b/CHANGELOG
index b7f9b1b326..7f3edb7297 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add start and stop buttons on works
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
* Make work center not required on request and draft states
diff --git a/tests/scenario_production_work.rst b/tests/scenario_production_work.rst
index ae85cabbb0..6d188aa376 100644
--- a/tests/scenario_production_work.rst
+++ b/tests/scenario_production_work.rst
@@ -214,17 +214,16 @@ Run works::
>>> work2.reload()
>>> work2.state
'draft'
- >>> cycle2 = work2.cycles.new()
- >>> cycle2.click('run')
- >>> cycle2.state
- 'running'
+ >>> work2.click('start')
+ >>> cycle2, = [c for c in work2.active_cycles]
>>> cycle2.duration = datetime.timedelta(hours=1)
- >>> cycle2.click('do')
- >>> cycle2.state
- 'done'
- >>> work2.reload()
+ >>> cycle2.save()
+ >>> work2.click('stop')
>>> work2.state
'finished'
+ >>> cycle2.reload()
+ >>> cycle2.state
+ 'done'
Add an extra work::
diff --git a/view/work_form.xml b/view/work_form.xml
index 70db0e226d..3fe5289592 100644
--- a/view/work_form.xml
+++ b/view/work_form.xml
@@ -12,7 +12,11 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
+
+
+
diff --git a/work.py b/work.py
index d09912fe5a..7af4642f1a 100644
--- a/work.py
+++ b/work.py
@@ -130,6 +130,12 @@ class Work(sequence_ordered(), ModelSQL, ModelView):
'readonly': Eval('state').in_(['request', 'done']),
},
depends=['state'])
+ active_cycles = fields.One2Many(
+ 'production.work.cycle', 'work', "Active Cycles",
+ readonly=True,
+ filter=[
+ ('state', '=', 'running'),
+ ])
company = fields.Many2One('company.company', 'Company', required=True,
select=True)
warehouse = fields.Function(fields.Many2One('stock.location', 'Warehouse'),
@@ -143,6 +149,21 @@ class Work(sequence_ordered(), ModelSQL, ModelView):
('done', 'Done'),
], 'State', select=True, readonly=True)
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ cls._buttons.update({
+ 'start': {
+ 'invisible': Bool(Eval('active_cycles', [])),
+ 'readonly': Eval('state').in_(['request', 'done']),
+ 'depends': ['active_cycles'],
+ },
+ 'stop': {
+ 'invisible': ~Bool(Eval('active_cycles', [])),
+ 'depends': ['active_cycles'],
+ },
+ })
+
@classmethod
def __register__(cls, module_name):
@@ -170,6 +191,27 @@ class Work(sequence_ordered(), ModelSQL, ModelView):
def default_state(cls):
return 'request'
+ @classmethod
+ @ModelView.button
+ def start(cls, works):
+ pool = Pool()
+ Cycle = pool.get('production.work.cycle')
+ cycles = [Cycle(work=w) for w in works]
+ Cycle.save(cycles)
+ Cycle.run(cycles)
+
+ @classmethod
+ @ModelView.button
+ def stop(cls, works):
+ pool = Pool()
+ Cycle = pool.get('production.work.cycle')
+
+ to_do = []
+ for work in works:
+ for cycle in work.active_cycles:
+ to_do.append(cycle)
+ Cycle.do(to_do)
+
@property
def _state(self):
if self.production.state == 'waiting':
diff --git a/work.xml b/work.xml
index 029bad1023..5aa98857b9 100644
--- a/work.xml
+++ b/work.xml
@@ -240,6 +240,18 @@ this repository contains the full copyright notices and license terms. -->
+
+ start
+ Start
+
+
+
+
+ stop
+ Stop
+
+
+
User in company