From 311d8ebf218c3cfde2d9d276d5031f0d95f1fc83 Mon Sep 17 00:00:00 2001 From: yofet Date: Wed, 2 Dec 2026 16:47:44 +0000 Subject: [PATCH] [MIG] queue_job_batch: Migration to 20.0 --- .pre-commit-config.yaml | 1 - queue_job_batch/README.rst | 16 +- queue_job_batch/__manifest__.py | 13 +- queue_job_batch/controllers/webclient.py | 26 ++- .../data/queue_job_channel_data.xml | 3 +- .../data/queue_job_function_data.xml | 1 + queue_job_batch/models/queue_job.py | 4 +- queue_job_batch/models/queue_job_batch.py | 13 +- queue_job_batch/models/res_users.py | 22 +- queue_job_batch/security/ir.access.csv | 5 + queue_job_batch/security/ir.model.access.csv | 4 - queue_job_batch/security/security.xml | 55 +---- queue_job_batch/static/description/index.html | 40 ++-- queue_job_batch/static/src/MailCoreWeb.esm.js | 18 +- .../static/src/QueueJobBatchModel.esm.js | 17 +- queue_job_batch/static/src/Store.esm.js | 24 +-- .../src/components/QueueJobBatchMenu.esm.js | 19 +- .../src/components/QueueJobBatchMenu.xml | 47 +++-- queue_job_batch/tests/__init__.py | 1 + queue_job_batch/tests/test_queue_job_batch.py | 194 ++++++++++++++++++ .../views/queue_job_batch_views.xml | 31 ++- queue_job_batch/views/queue_job_views.xml | 2 +- 22 files changed, 361 insertions(+), 195 deletions(-) create mode 100644 queue_job_batch/security/ir.access.csv delete mode 100644 queue_job_batch/security/ir.model.access.csv create mode 100644 queue_job_batch/tests/__init__.py create mode 100644 queue_job_batch/tests/test_queue_job_batch.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cdbd3cf757..2bb10bbac6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,6 @@ exclude: | (?x) # NOT INSTALLABLE ADDONS ^base_import_async/| - ^queue_job_batch/| ^queue_job_cron/| ^queue_job_cron_jobrunner/| ^queue_job_subscribe/| diff --git a/queue_job_batch/README.rst b/queue_job_batch/README.rst index d0b9d22c38..481a030ac2 100644 --- a/queue_job_batch/README.rst +++ b/queue_job_batch/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + =============== Job Queue Batch =============== @@ -13,17 +17,17 @@ Job Queue Batch .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github - :target: https://github.com/OCA/queue/tree/18.0/queue_job_batch + :target: https://github.com/OCA/queue/tree/20.0/queue_job_batch :alt: OCA/queue .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_batch + :target: https://translation.odoo-community.org/projects/queue-20-0/queue-20-0-queue_job_batch :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=20.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -82,7 +86,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -132,6 +136,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/queue `_ project on GitHub. +This module is part of the `OCA/queue `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/queue_job_batch/__manifest__.py b/queue_job_batch/__manifest__.py index 12dc679b8f..9e82958590 100644 --- a/queue_job_batch/__manifest__.py +++ b/queue_job_batch/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Job Queue Batch", - "version": "18.0.1.0.0", + "version": "20.0.1.0.0", "author": "Creu Blanca,Odoo Community Association (OCA)", "website": "https://github.com/OCA/queue", "license": "AGPL-3", @@ -13,12 +13,12 @@ "queue_job", ], "data": [ + # security + "security/security.xml", + "security/ir.access.csv", # data "data/queue_job_channel_data.xml", "data/queue_job_function_data.xml", - # security - "security/security.xml", - "security/ir.model.access.csv", # views "views/queue_job_views.xml", "views/queue_job_batch_views.xml", @@ -29,7 +29,6 @@ "queue_job_batch/static/src/**/*.xml", "queue_job_batch/static/src/**/*.scss", ], - 'installable': False, -}, - 'installable': False, + }, + "installable": True, } diff --git a/queue_job_batch/controllers/webclient.py b/queue_job_batch/controllers/webclient.py index 8967932795..65fdf83fb7 100644 --- a/queue_job_batch/controllers/webclient.py +++ b/queue_job_batch/controllers/webclient.py @@ -4,20 +4,18 @@ from odoo.http import request from odoo.addons.mail.controllers.webclient import WebclientController +from odoo.addons.mail.tools.discuss import Store +from odoo.addons.mail.tools.store_handler import store_handler class WebClient(WebclientController): - def _process_request_for_internal_user(self, store, **kwargs): - res = super()._process_request_for_internal_user(store, **kwargs) - if kwargs.get("systray_get_queue_job_batches"): - # sudo: bus.bus: reading non-sensitive last id - bus_last_id = request.env["bus.bus"].sudo()._bus_last_id() - batches = request.env.user._get_queue_job_batches() - store.add(batches) - store.add( - { - "queueJobBatchCounter": len(batches), - "queueJobBatchCounterBusId": bus_last_id, - } - ) - return res + @store_handler("systray_get_queue_job_batches") + def store_systray_get_queue_job_batches(self, store: Store): + # sudo: bus.bus: reading non-sensitive last id + bus_last_id = request.env["bus.bus"].sudo()._bus_last_id() + batches = request.env.user._get_queue_job_batches() + store.add(batches, "_store_queue_job_batch_fields") + store.add_global_values( + queueJobBatchCounter=len(batches), + queueJobBatchCounterBusId=bus_last_id, + ) diff --git a/queue_job_batch/data/queue_job_channel_data.xml b/queue_job_batch/data/queue_job_channel_data.xml index 04dd328c59..41479b337c 100644 --- a/queue_job_batch/data/queue_job_channel_data.xml +++ b/queue_job_batch/data/queue_job_channel_data.xml @@ -1,5 +1,6 @@ + - + queue.job.batch diff --git a/queue_job_batch/data/queue_job_function_data.xml b/queue_job_batch/data/queue_job_function_data.xml index c9606d4f6d..79cb39a2a4 100644 --- a/queue_job_batch/data/queue_job_function_data.xml +++ b/queue_job_batch/data/queue_job_function_data.xml @@ -1,3 +1,4 @@ + diff --git a/queue_job_batch/models/queue_job.py b/queue_job_batch/models/queue_job.py index ddc3efe879..1ac10b7872 100644 --- a/queue_job_batch/models/queue_job.py +++ b/queue_job_batch/models/queue_job.py @@ -28,5 +28,7 @@ def write(self, vals): for batch in batches: # We need to make it with delay in order to prevent two jobs # to work with the same batch - batch.with_delay(identity_key=identity_exact).check_state() + batch.with_context(job_batch=False).with_delay( + identity_key=identity_exact + ).check_state() return super().write(vals) diff --git a/queue_job_batch/models/queue_job_batch.py b/queue_job_batch/models/queue_job_batch.py index 998f7a5ac2..de02ecb8f6 100644 --- a/queue_job_batch/models/queue_job_batch.py +++ b/queue_job_batch/models/queue_job_batch.py @@ -9,7 +9,7 @@ class QueueJobBatch(models.Model): _name = "queue.job.batch" - _inherit = ["mail.thread", "mail.activity.mixin"] + _inherit = ["mail.thread", "mail.activity.mixin"] # noqa: RUF012 _description = "Batch of jobs" _log_access = False @@ -111,7 +111,7 @@ def _compute_job_count(self): @api.model def _to_store_fnames(self): - return ( + return [ "name", "state", "job_count", @@ -119,10 +119,7 @@ def _to_store_fnames(self): "failed_job_count", "completeness", "failed_percentage", - ) + ] - def _to_store(self, store: Store): - fnames = self._to_store_fnames() - for rec in self: - data = rec.read(fnames)[0] - store.add(rec, data) + def _store_queue_job_batch_fields(self, res: Store.FieldList): + res.extend(self._to_store_fnames()) diff --git a/queue_job_batch/models/res_users.py b/queue_job_batch/models/res_users.py index de53d2b31f..5cb30bcf90 100644 --- a/queue_job_batch/models/res_users.py +++ b/queue_job_batch/models/res_users.py @@ -3,24 +3,22 @@ from odoo import models +from odoo.addons.mail.tools.discuss import Store + class Users(models.Model): - _name = "res.users" - _inherit = ["res.users"] + _inherit = "res.users" - def _init_store_data(self, store): - res = super()._init_store_data(store) - store.add( - { - "hasQueueJobBatchUserGroup": self.env.user.has_group( - "queue_job_batch.group_queue_job_batch_user" - ), - } + def _store_init_global_fields(self, res: Store.FieldList): + result = super()._store_init_global_fields(res) + res.attr( + "hasQueueJobBatchUserGroup", + self.env.user.has_group("queue_job_batch.group_queue_job_batch_user"), ) - return res + return result def _get_queue_job_batches(self): - # See :meth:`controllers.webclient.WebClient._process_request_for_internal_user` + # See controllers.webclient.WebClient.store_systray_get_queue_job_batches self.ensure_one() return self.env["queue.job.batch"].search( [ diff --git a/queue_job_batch/security/ir.access.csv b/queue_job_batch/security/ir.access.csv new file mode 100644 index 0000000000..971294d419 --- /dev/null +++ b/queue_job_batch/security/ir.access.csv @@ -0,0 +1,5 @@ +id,name,model_id,group_id/id,operation,domain +access_queue_job_batch_user,queue job batch user,queue.job.batch,queue_job_batch.group_queue_job_batch_user,ru,"[('user_id', '=', user.id)]" +access_queue_job_batch_manager,queue job batch manager,queue.job.batch,queue_job.group_queue_job_manager,crud, +queue_job_batch_comp_rule,Job Queue batch multi-company,queue.job.batch,,crud,"['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]" +access_queue_job_queue_job_batch_user,queue job batch queue.job user,queue.job,queue_job_batch.group_queue_job_batch_user,r, diff --git a/queue_job_batch/security/ir.model.access.csv b/queue_job_batch/security/ir.model.access.csv deleted file mode 100644 index e3da256bbb..0000000000 --- a/queue_job_batch/security/ir.model.access.csv +++ /dev/null @@ -1,4 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_queue_job_batch_user,queue job manager,model_queue_job_batch,group_queue_job_batch_user,1,1,0,0 -access_queue_job_batch_manager,queue job manager,model_queue_job_batch,queue_job.group_queue_job_manager,1,1,1,1 -access_queue_job_queue_job_batch_user,queue job manager,queue_job.model_queue_job,group_queue_job_batch_user,1,0,0,0 diff --git a/queue_job_batch/security/security.xml b/queue_job_batch/security/security.xml index 9443708ae0..38b2b2c78d 100644 --- a/queue_job_batch/security/security.xml +++ b/queue_job_batch/security/security.xml @@ -1,46 +1,13 @@ - + - - - Job Queue Batch User - - - - - - - - - - Job Queue batch multi-company - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - - - - Job Queue batch user filter - - - [('user_id', '=', user.id)] - - - - Job Queue batch manager - - - [(1, '=', 1)] - - + + Job Queue Batch User + + + + + diff --git a/queue_job_batch/static/description/index.html b/queue_job_batch/static/description/index.html index 455c0ecf78..40cf7dcf1f 100644 --- a/queue_job_batch/static/description/index.html +++ b/queue_job_batch/static/description/index.html @@ -360,36 +360,41 @@ -
-

Job Queue Batch

+
+ + +Odoo Community Association + +
+

Job Queue Batch

-

Beta License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

This addon adds an a grouper for queue jobs.

It allows to show your jobs in a batched form in order to know better the results.

Example:

-from odoo import models, fields, api
+from odoo import models, fields, api
 
 
-class MyModel(models.Model):
+class MyModel(models.Model):
     _name = 'my.model'
 
-    def my_method(self, a, k=None):
+    def my_method(self, a, k=None):
         _logger.info('executed with a: %s and k: %s', a, k)
 
 
-class MyOtherModel(models.Model):
+class MyOtherModel(models.Model):
     _name = 'my.other.model'
 
     @api.multi
-    def button_do_stuff(self):
+    def button_do_stuff(self):
         batch = self.env['queue.job.batch'].get_new_batch('Group')
         model = self.env['my.model'].with_context(job_batch=batch)
         for i in range(1, 100):
@@ -415,29 +420,29 @@ 

Job Queue Batch

-

Usage

+

Usage

You can manage your batch jobs from the Systray. A new button will be shown with your currently executing job batches and the recently finished job groups.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Creu Blanca
-

Contributors

+

Contributors

-

Other credits

+

Other credits

The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -470,10 +475,11 @@

Maintainers

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/queue project on GitHub.

+

This module is part of the OCA/queue project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
diff --git a/queue_job_batch/static/src/MailCoreWeb.esm.js b/queue_job_batch/static/src/MailCoreWeb.esm.js index 2d37b02b0f..b8e841113f 100644 --- a/queue_job_batch/static/src/MailCoreWeb.esm.js +++ b/queue_job_batch/static/src/MailCoreWeb.esm.js @@ -7,17 +7,17 @@ patch(MailCoreWeb.prototype, { this.busService.subscribe( "queue.job.batch/updated", (payload, {id: notifId}) => { - if ( - payload.batch_created && - notifId > this.store.queueJobBatchCounterBusId - ) { + if (notifId <= this.store.queueJobBatchCounterBusId) { + return; + } + if (payload.batch_created) { this.store.queueJobBatchCounter++; } - if ( - payload.batch_read && - notifId > this.store.queueJobBatchCounterBusId - ) { - this.store.queueJobBatchCounter--; + if (payload.batch_read) { + this.store.queueJobBatchCounter = Math.max( + this.store.queueJobBatchCounter - 1, + 0 + ); } } ); diff --git a/queue_job_batch/static/src/QueueJobBatchModel.esm.js b/queue_job_batch/static/src/QueueJobBatchModel.esm.js index cb5cd4d4fb..06480b190c 100644 --- a/queue_job_batch/static/src/QueueJobBatchModel.esm.js +++ b/queue_job_batch/static/src/QueueJobBatchModel.esm.js @@ -1,21 +1,8 @@ -import {Record} from "@mail/core/common/record"; +import {Record} from "@mail/model/export"; import {_t} from "@web/core/l10n/translation"; export class QueueJobBatch extends Record { - static id = "id"; - - /** @type {Object.} */ - static records = {}; - - /** @returns {QueueJobBatch} */ - static get() { - return super.get(...arguments); - } - - /** @returns {QueueJobBatch|QueueJobBatch[]} */ - static insert() { - return super.insert(...arguments); - } + static _name = "queue.job.batch"; /** @type {Number} */ id; diff --git a/queue_job_batch/static/src/Store.esm.js b/queue_job_batch/static/src/Store.esm.js index 619d7090b0..2c8e44b21b 100644 --- a/queue_job_batch/static/src/Store.esm.js +++ b/queue_job_batch/static/src/Store.esm.js @@ -2,21 +2,21 @@ Copyright 2025 Camptocamp SA (https://www.camptocamp.com). License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ -import {Store, pyToJsModels} from "@mail/core/common/store_service"; +import {Store} from "@mail/core/common/store_service"; import {patch} from "@web/core/utils/patch"; -pyToJsModels["queue.job.batch"] = "QueueJobBatch"; - patch(Store.prototype, { - hasQueueJobBatchUserGroup: false, - queueJobBatchCounterBusId: 0, - queueJobBatchCounter: 0, + setup() { + super.setup(...arguments); + this.hasQueueJobBatchUserGroup = false; + this.queueJobBatchCounterBusId = 0; + this.queueJobBatchCounter = 0; + }, - /** @override */ - get initMessagingParams() { - return { - ...super.initMessagingParams, - systray_get_queue_job_batches: true, - }; + initialize() { + super.initialize(...arguments); + if (this.self_user?.share === false && this.hasQueueJobBatchUserGroup) { + this.fetchStoreData("systray_get_queue_job_batches"); + } }, }); diff --git a/queue_job_batch/static/src/components/QueueJobBatchMenu.esm.js b/queue_job_batch/static/src/components/QueueJobBatchMenu.esm.js index a8addd461b..a21f1d8394 100644 --- a/queue_job_batch/static/src/components/QueueJobBatchMenu.esm.js +++ b/queue_job_batch/static/src/components/QueueJobBatchMenu.esm.js @@ -3,36 +3,39 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ -import {Component, useState} from "@odoo/owl"; import {ColumnProgress} from "@web/views/view_components/column_progress"; +import {Component} from "@odoo/owl"; import {Dropdown} from "@web/core/dropdown/dropdown"; +import {_t} from "@web/core/l10n/translation"; import {registry} from "@web/core/registry"; import {useDiscussSystray} from "@mail/utils/common/hooks"; import {useDropdownState} from "@web/core/dropdown/dropdown_hooks"; import {useService} from "@web/core/utils/hooks"; import {user} from "@web/core/user"; -import {_t} from "@web/core/l10n/translation"; export class QueueJobBatchMenu extends Component { static template = "queue_job_batch.QueueJobBatchMenu"; static components = {Dropdown, ColumnProgress}; - static props = []; /** * @override */ setup() { super.setup(); - this.discussSystray = useDiscussSystray(); - this.store = useState(useService("mail.store")); + this.dropdown = useDropdownState(); + this.discussSystray = useDiscussSystray(this.dropdown); + this.store = useService("mail.store"); this.action = useService("action"); this.userId = user.userId; - this.ui = useState(useService("ui")); - this.dropdown = useDropdownState(); + this.ui = useService("ui"); + } + + get jobBatches() { + return [...this.store["queue.job.batch"].records.values()]; } onBeforeOpen() { - this.store.fetchData({systray_get_queue_job_batches: true}); + this.store.fetchStoreData("systray_get_queue_job_batches"); } getGroupInfo(batch) { diff --git a/queue_job_batch/static/src/components/QueueJobBatchMenu.xml b/queue_job_batch/static/src/components/QueueJobBatchMenu.xml index d43103d16f..393d454904 100644 --- a/queue_job_batch/static/src/components/QueueJobBatchMenu.xml +++ b/queue_job_batch/static/src/components/QueueJobBatchMenu.xml @@ -6,26 +6,31 @@
No jobs to view. @@ -35,7 +40,7 @@ name="queueJobBatches" > @@ -46,29 +51,32 @@
- +