changeset a12ef09b36cd in modules/production_work:default
details: 
https://hg.tryton.org/modules/production_work?cmd=changeset;node=a12ef09b36cd
description:
        Add start and stop buttons on works

        issue9418
        review317661005
diffstat:

 CHANGELOG                          |   2 +
 tests/scenario_production_work.rst |  15 ++++++-------
 view/work_form.xml                 |   6 ++++-
 work.py                            |  42 ++++++++++++++++++++++++++++++++++++++
 work.xml                           |  12 ++++++++++
 5 files changed, 68 insertions(+), 9 deletions(-)

diffs (141 lines):

diff -r 9da24b313d9b -r a12ef09b36cd CHANGELOG
--- a/CHANGELOG Wed Jul 22 08:51:02 2020 +0200
+++ b/CHANGELOG Mon Oct 12 19:24:42 2020 +0200
@@ -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 -r 9da24b313d9b -r a12ef09b36cd tests/scenario_production_work.rst
--- a/tests/scenario_production_work.rst        Wed Jul 22 08:51:02 2020 +0200
+++ b/tests/scenario_production_work.rst        Mon Oct 12 19:24:42 2020 +0200
@@ -214,17 +214,16 @@
     >>> 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.save()
+    >>> work2.click('stop')
+    >>> work2.state
+    'finished'
+    >>> cycle2.reload()
     >>> cycle2.state
     'done'
-    >>> work2.reload()
-    >>> work2.state
-    'finished'
 
 Add an extra work::
 
diff -r 9da24b313d9b -r a12ef09b36cd view/work_form.xml
--- a/view/work_form.xml        Wed Jul 22 08:51:02 2020 +0200
+++ b/view/work_form.xml        Mon Oct 12 19:24:42 2020 +0200
@@ -12,7 +12,11 @@
     <field name="operation"/>
     <label name="work_center"/>
     <field name="work_center"/>
-    <field name="cycles" mode="form,tree" colspan="4"/>
+    <group id="buttons" colspan="4">
+        <button name="start" icon="tryton-launch"/>
+        <button name="stop" icon="tryton-ok"/>
+    </group>
+    <field name="cycles" colspan="4"/>
     <label id="empty" colspan="2"/>
     <label name="state"/>
     <field name="state"/>
diff -r 9da24b313d9b -r a12ef09b36cd work.py
--- a/work.py   Wed Jul 22 08:51:02 2020 +0200
+++ b/work.py   Mon Oct 12 19:24:42 2020 +0200
@@ -130,6 +130,12 @@
             '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'),
@@ -144,6 +150,21 @@
             ], '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):
 
         super().__register__(module_name)
@@ -170,6 +191,27 @@
     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 -r 9da24b313d9b -r a12ef09b36cd work.xml
--- a/work.xml  Wed Jul 22 08:51:02 2020 +0200
+++ b/work.xml  Mon Oct 12 19:24:42 2020 +0200
@@ -240,6 +240,18 @@
             <field name="perm_delete" eval="True"/>
         </record>
 
+        <record model="ir.model.button" id="work_start_button">
+            <field name="name">start</field>
+            <field name="string">Start</field>
+            <field name="model" search="[('model', '=', 'production.work')]"/>
+        </record>
+
+        <record model="ir.model.button" id="work_stop_button">
+            <field name="name">stop</field>
+            <field name="string">Stop</field>
+            <field name="model" search="[('model', '=', 'production.work')]"/>
+        </record>
+
         <record model="ir.rule.group" id="rule_group_work">
             <field name="name">User in company</field>
             <field name="model" search="[('model', '=', 'production.work')]"/>

Reply via email to