Add start and stop buttons on works
issue9418 review317661005
This commit is contained in:
1 parent
6ea8000d0e
commit
ef41e92000
5 files changed
+68
-9
No files matched your search
@@ -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
|
||||
|
||||
@@ -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::
|
||||
|
||||
|
||||
+5
-1
@@ -12,7 +12,11 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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"/>
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -240,6 +240,18 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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')]"/>
|
||||
|
||||
Reference in new issue
Block a user