Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #241 from OpenSPP/program_root_channel
Browse files Browse the repository at this point in the history
created new root channel for job queue and use it to id batch printing
  • Loading branch information
jeremi authored Jun 5, 2023
2 parents 21bf693 + 567b005 commit c7dcfab
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 3 deletions.
8 changes: 7 additions & 1 deletion spp_idqueue/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
"license": "LGPL-3",
"development_status": "Beta",
"maintainers": ["jeremi", "gonzalesedwin1123"],
"depends": ["base", "g2p_registry_base", "spp_idpass"],
"depends": [
"base",
"g2p_registry_base",
"spp_idpass",
"queue_job",
],
"data": [
"data/id_pass.xml",
"data/queue_data.xml",
"security/g2p_security.xml",
"security/ir.model.access.csv",
"views/id_queue_view.xml",
Expand Down
10 changes: 10 additions & 0 deletions spp_idqueue/data/queue_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="queue.job.channel" id="channel_root_id_batch">
<field name="name">root_id_batch</field>
</record>
<record model="queue.job.channel" id="channel_id_batch">
<field name="name">id_batch</field>
<field name="parent_id" ref="channel_root_id_batch" />
</record>
</odoo>
1 change: 1 addition & 0 deletions spp_idqueue/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import id_queue
from . import id_batch
from . import registrant
from . import queue_job_channel
10 changes: 8 additions & 2 deletions spp_idqueue/models/id_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ def _generate_batch(self, batch_ids):
ctr_ids += 1
queued_ids.append(queued_id.id)
if (ctr % self.JOBBATCH_SIZE == 0) or ctr == max_rec:
jobs.append(rec.delayable()._generate_cards(queued_ids))
jobs.append(
rec.delayable(channel="root_id_batch.id_batch")._generate_cards(
queued_ids
)
)
queued_ids = []

main_job = group(*jobs)
main_job.on_done(self.delayable().mark_as_done(rec))
main_job.on_done(
self.delayable(channel="root_id_batch.id_batch").mark_as_done(rec)
)
main_job.delay()

message_1 = _("{} started to generate this batch on {}.").format(
Expand Down
16 changes: 16 additions & 0 deletions spp_idqueue/models/queue_job_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import _, api, exceptions, models


class CustomQueueJobChannel(models.Model):
_inherit = "queue.job.channel"

@api.constrains("parent_id", "name")
def parent_required(self):
for record in self:
if (
record.name
and not record.name.startswith("root")
and not record.parent_id
):
raise exceptions.ValidationError(_("Parent channel required."))
return
1 change: 1 addition & 0 deletions spp_idqueue/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import test_registrant
from . import test_request_id_wizard
from . import test_res_config_settings
from . import test_queue_job_channel
11 changes: 11 additions & 0 deletions spp_idqueue/tests/test_queue_job_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo.exceptions import ValidationError

from .common import Common


class TestCustomQueueJobChannel(Common):
def test_01_parent_required(self):
with self.assertRaisesRegex(ValidationError, "Parent channel required."):
self.env["queue.job.channel"].create({"name": "channel_program"})

self.env["queue.job.channel"].create({"name": "root_test"})

0 comments on commit c7dcfab

Please sign in to comment.