From 57d27480aebd9087eb722efe0daf7c0b26117131 Mon Sep 17 00:00:00 2001 From: Yannis Burkhalter Date: Wed, 16 Nov 2022 14:29:55 +0100 Subject: [PATCH] [MIG] contract_queue_job: Migration to 14.0 --- contract_queue_job/README.rst | 27 ++++++++----- contract_queue_job/__init__.py | 1 - contract_queue_job/__manifest__.py | 8 +++- .../data/ir_config_parameter.xml | 8 ++++ .../models/contract_contract.py | 25 +++++++----- contract_queue_job/models/contract_line.py | 19 +++++++--- contract_queue_job/readme/USAGE.rst | 2 + .../static/description/index.html | 38 +++++++++++-------- .../tests/test_contract_line_queue_job.py | 21 ++++++++++ .../tests/test_contract_queue_job.py | 17 +++++++-- .../contract_manually_create_invoice.py | 5 +-- .../contract_manually_create_invoice.xml | 21 ++++++++++ 12 files changed, 142 insertions(+), 50 deletions(-) create mode 100644 contract_queue_job/data/ir_config_parameter.xml create mode 100644 contract_queue_job/readme/USAGE.rst create mode 100644 contract_queue_job/wizards/contract_manually_create_invoice.xml diff --git a/contract_queue_job/README.rst b/contract_queue_job/README.rst index ce587ffb0..3806c0e47 100644 --- a/contract_queue_job/README.rst +++ b/contract_queue_job/README.rst @@ -14,14 +14,14 @@ Contract Queue Job :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github - :target: https://github.com/OCA/contract/tree/12.0/contract_queue_job + :target: https://github.com/OCA/contract/tree/14.0/contract_queue_job :alt: OCA/contract .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-contract_queue_job + :target: https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-contract_queue_job :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/110/12.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/contract&target_branch=14.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -32,13 +32,19 @@ This addon make contract invoicing cron plan each contract in a job instead of c .. contents:: :local: +Usage +===== + +The feature can be enabled by setting the ir.config_parameter +"contract.queue.job" to True. + 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 smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -71,11 +77,14 @@ promote its widespread use. .. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px :target: https://github.com/sbejaoui :alt: sbejaoui +.. |maintainer-BurkhalterY| image:: https://github.com/BurkhalterY.png?size=40px + :target: https://github.com/BurkhalterY + :alt: BurkhalterY -Current `maintainer `__: +Current `maintainers `__: -|maintainer-sbejaoui| +|maintainer-sbejaoui| |maintainer-BurkhalterY| -This module is part of the `OCA/contract `_ project on GitHub. +This module is part of the `OCA/contract `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/contract_queue_job/__init__.py b/contract_queue_job/__init__.py index 1c15bc7ee..aee8895e7 100644 --- a/contract_queue_job/__init__.py +++ b/contract_queue_job/__init__.py @@ -1,3 +1,2 @@ from . import models from . import wizards -from . import tests diff --git a/contract_queue_job/__manifest__.py b/contract_queue_job/__manifest__.py index 50a967559..dca19647b 100644 --- a/contract_queue_job/__manifest__.py +++ b/contract_queue_job/__manifest__.py @@ -6,10 +6,14 @@ "summary": """ This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction""", - "version": "12.0.1.1.0", + "version": "14.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/contract", "depends": ["contract", "queue_job"], - "maintainers": ["sbejaoui"], + "data": [ + "data/ir_config_parameter.xml", + "wizards/contract_manually_create_invoice.xml", + ], + "maintainers": ["sbejaoui", "BurkhalterY"], } diff --git a/contract_queue_job/data/ir_config_parameter.xml b/contract_queue_job/data/ir_config_parameter.xml new file mode 100644 index 000000000..fa02eaab9 --- /dev/null +++ b/contract_queue_job/data/ir_config_parameter.xml @@ -0,0 +1,8 @@ + + + + contract.queue.job + + False + + diff --git a/contract_queue_job/models/contract_contract.py b/contract_queue_job/models/contract_contract.py index ad44091e8..fc5b1db3c 100644 --- a/contract_queue_job/models/contract_contract.py +++ b/contract_queue_job/models/contract_contract.py @@ -1,23 +1,28 @@ # Copyright 2020 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import ast -from odoo import api, models - -from odoo.addons.queue_job.job import job - -QUEUE_CHANNEL = "root.CONTRACT_INVOICE" +from odoo import models class ContractContract(models.Model): _inherit = "contract.contract" - @api.multi - @job(default_channel=QUEUE_CHANNEL) def _recurring_create_invoice(self, date_ref=False): - res = self.env["account.invoice"] - if len(self) > 1: + as_job = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("contract.queue.job", default=False) + ) + + try: + as_job = ast.literal_eval(as_job) if as_job else False + except ValueError: + as_job = False + + if as_job and len(self) > 1: for rec in self: rec.with_delay()._recurring_create_invoice(date_ref=date_ref) - return res + return self.env["account.move"] return super()._recurring_create_invoice(date_ref=date_ref) diff --git a/contract_queue_job/models/contract_line.py b/contract_queue_job/models/contract_line.py index 62d8806fb..41850d55f 100644 --- a/contract_queue_job/models/contract_line.py +++ b/contract_queue_job/models/contract_line.py @@ -1,20 +1,27 @@ # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import ast from odoo import models -from odoo.addons.queue_job.job import job - -QUEUE_CHANNEL = "root.CONTRACT_LINE_RENEW" - class ContractLine(models.Model): _inherit = "contract.line" - @job(default_channel=QUEUE_CHANNEL) def renew(self): - if len(self) > 1: + as_job = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("contract.queue.job", default=False) + ) + + try: + as_job = ast.literal_eval(as_job) if as_job else False + except ValueError: + as_job = False + + if as_job and len(self) > 1: for rec in self: rec.with_delay().renew() return self.env["contract.line"] diff --git a/contract_queue_job/readme/USAGE.rst b/contract_queue_job/readme/USAGE.rst new file mode 100644 index 000000000..334887b74 --- /dev/null +++ b/contract_queue_job/readme/USAGE.rst @@ -0,0 +1,2 @@ +The feature can be enabled by setting the ir.config_parameter +"contract.queue.job" to True. diff --git a/contract_queue_job/static/description/index.html b/contract_queue_job/static/description/index.html index 964106820..58a6a3871 100644 --- a/contract_queue_job/static/description/index.html +++ b/contract_queue_job/static/description/index.html @@ -3,7 +3,7 @@ - + Contract Queue Job