Skip to content
Permalink
Browse files

[10.0] queue_job: reason to set to done

  • Loading branch information...
baimont authored and OCA-git-bot committed Apr 26, 2019
1 parent f28d55f commit 96d6dc931c9f06996474631f96321a315f282648
Showing with 39 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +23 −3 queue_job/models/queue_job.py
  3. +7 −2 queue_job/views/queue_job_views.xml
  4. +8 −0 test_queue_job/tests/test_job.py
@@ -21,6 +21,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
*.eggs

# Installer logs
pip-log.txt
@@ -161,11 +161,29 @@ def _change_job_state(self, state, result=None):
job_.store()

@api.multi
def button_done(self):
result = _('Manually set to done by %s') % self.env.user.name
def action_done(self, reason=None):
result = _(
u"Manually set to done by {}"
).format(self.env.user.name)
if reason:
result = _(
u"{} with reason: {}"
).format(result, reason)
self._change_job_state(DONE, result=result)
return True

@api.multi
def button_done(self):
_logger.warning('deprecated, replaced by action_done()')
return self.action_done()

@api.multi
def button_done_ask_reason(self):
action = self.env.ref(
'queue_job.action_set_jobs_done'
).read()[0]
return action

@api.multi
def requeue(self):
self._change_job_state(PENDING)
@@ -296,10 +314,12 @@ class SetJobsToDone(models.TransientModel):
_name = 'queue.jobs.to.done'
_description = 'Set all selected jobs to done'

reason = fields.Text(string='Reason to set to done')

@api.multi
def set_done(self):
jobs = self.job_ids
jobs.button_done()
jobs.action_done(reason=self.reason)
return {'type': 'ir.actions.act_window_close'}


@@ -14,7 +14,7 @@
string="Requeue Job"
type="object"
groups="queue_job.group_queue_job_manager"/>
<button name="button_done"
<button name="button_done_ask_reason"
states="pending,enqueued,failed"
class="oe_highlight"
string="Set to 'Done'"
@@ -162,7 +162,12 @@
<field name="arch" type="xml">
<form string="Set jobs done">
<group string="The selected jobs will be set to done.">
<field name="job_ids" nolabel="1"/>
<group>
<field name="reason"/>
</group>
<group>
<field name="job_ids" nolabel="1"/>
</group>
</group>
<footer>
<button name="set_done" string="Set to done" type="object" class="oe_highlight"/>
@@ -480,6 +480,14 @@ def test_button_done(self):
self.assertEqual(stored.result,
'Manually set to done by %s' % self.env.user.name)

def test_action_done(self):
stored = self._create_job()
stored.action_done(reason="reason")
self.assertEqual(stored.state, DONE)
self.assertEqual(stored.result,
'Manually set to done by %s with reason: reason'
% self.env.user.name)

def test_requeue(self):
stored = self._create_job()
stored.write({'state': 'failed'})

0 comments on commit 96d6dc9

Please sign in to comment.
You can’t perform that action at this time.