[IMP] attachment_queue : add possibility to re-schedule attachments in batch

pull/2560/head
Florian da Costa 2023-05-18 09:17:58 +02:00
parent e7754cd9e0
commit 9d2c61e3b4
7 changed files with 78 additions and 0 deletions

View File

@ -1 +1,2 @@
from . import models
from . import wizards

View File

@ -16,6 +16,7 @@
"security/ir.model.access.csv",
"data/mail_template.xml",
"data/queue_job_channel.xml",
"wizards/attachement_queue_reschedule.xml",
],
"demo": ["demo/attachment_queue.xml"],
"installable": True,

View File

@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_attachment_queue_user,attachment.queue.user,model_attachment_queue,,1,0,0,0
access_attachment_queue_manager,attachment.queue.manager,model_attachment_queue,base.group_no_one,1,1,1,1
access_attachment_reschedule_wizard,Attachment Queue Reschedule,attachment_queue.model_attachment_queue_reschedule,base.group_no_one,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_attachment_queue_user attachment.queue.user model_attachment_queue 1 0 0 0
3 access_attachment_queue_manager attachment.queue.manager model_attachment_queue base.group_no_one 1 1 1 1
4 access_attachment_reschedule_wizard Attachment Queue Reschedule attachment_queue.model_attachment_queue_reschedule base.group_no_one 1 1 1 1

View File

@ -134,3 +134,14 @@ class TestAttachmentBaseQueue(TransactionCase):
self.assertEqual(attachment.state, "pending")
attachment.set_done()
self.assertEqual(attachment.state, "done")
def test_reschedule_wizard(self):
attachment = self.env.ref("attachment_queue.dummy_attachment_queue")
attachment.write({"state": "failed"})
wizard = (
self.env["attachment.queue.reschedule"]
.with_context(active_model="attachment.queue", active_ids=attachment.ids)
.create({})
)
wizard.reschedule()
self.assertEqual(attachment.state, "pending")

View File

@ -0,0 +1 @@
from . import attachement_queue_reschedule

View File

@ -0,0 +1,29 @@
# Copyright 2013-2020 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from odoo import fields, models
class AttachmentQueueReschedule(models.TransientModel):
_name = "attachment.queue.reschedule"
_description = "Wizard to reschedule a selection of attachments"
def _default_attachment_ids(self):
res = False
context = self.env.context
if context.get("active_model") == "attachment.queue" and context.get(
"active_ids"
):
res = context["active_ids"]
return res
attachment_ids = fields.Many2many(
comodel_name="attachment.queue",
string="Attachments",
default=lambda r: r._default_attachment_ids(),
)
def reschedule(self):
attachments = self.attachment_ids
attachments.button_reschedule()
return {"type": "ir.actions.act_window_close"}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_reschedule_attachment" model="ir.ui.view">
<field name="name">Reschedule Attachments</field>
<field name="model">attachment.queue.reschedule</field>
<field name="arch" type="xml">
<form string="Requeue Attachments">
<group string="The selected attachments will be rescheduled.">
<field name="attachment_ids" nolabel="1" colspan="2" />
</group>
<footer>
<button
name="reschedule"
string="Reschedule"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_reschedule_attachment" model="ir.actions.act_window">
<field name="name">Reschedule Attachment</field>
<field name="res_model">attachment.queue.reschedule</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_reschedule_attachment" />
<field name="target">new</field>
<field name="binding_model_id" ref="attachment_queue.model_attachment_queue" />
</record>
</odoo>