From 793f06e7ba4faf29c8d7613699c53bd9d65f8069 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Tue, 17 Sep 2024 15:19:55 +0200 Subject: [PATCH] [IMP] queue_job_batch: inverse batch order This make latest created batch on top of notification list --- queue_job_batch/models/queue_job_batch.py | 1 + queue_job_batch/tests/__init__.py | 1 + queue_job_batch/tests/test_queue_job_batch.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 queue_job_batch/tests/__init__.py create mode 100644 queue_job_batch/tests/test_queue_job_batch.py diff --git a/queue_job_batch/models/queue_job_batch.py b/queue_job_batch/models/queue_job_batch.py index 09e925838c..1c00ce879d 100644 --- a/queue_job_batch/models/queue_job_batch.py +++ b/queue_job_batch/models/queue_job_batch.py @@ -11,6 +11,7 @@ class QueueJobBatch(models.Model): _inherit = ["mail.thread", "mail.activity.mixin"] _description = "Batch of jobs" _log_access = False + _order = "id desc" name = fields.Char( required=True, diff --git a/queue_job_batch/tests/__init__.py b/queue_job_batch/tests/__init__.py new file mode 100644 index 0000000000..39cec46423 --- /dev/null +++ b/queue_job_batch/tests/__init__.py @@ -0,0 +1 @@ +from . import test_queue_job_batch diff --git a/queue_job_batch/tests/test_queue_job_batch.py b/queue_job_batch/tests/test_queue_job_batch.py new file mode 100644 index 0000000000..37cf0e28c2 --- /dev/null +++ b/queue_job_batch/tests/test_queue_job_batch.py @@ -0,0 +1,17 @@ +from odoo.tests import SavepointCase + + +class TestQueueJobBatch(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.batch1 = cls.env["queue.job.batch"].get_new_batch("batch 1") + cls.batch2 = cls.env["queue.job.batch"].get_new_batch("batch 2") + + def test_default_order(self): + """we want latest batch on top of the notification list""" + batches = self.env["queue.job.batch"].search( + [("id", "in", (self.batch1 | self.batch2).ids)] + ) + self.assertEqual(batches[0].name, "batch 2") + self.assertEqual(batches[1].name, "batch 1")