[MIG] contract_queue_job: Migration to 14.0

This commit is contained in:
Yannis Burkhalter
2022-11-16 14:29:55 +01:00
committed by OCA-git-bot
parent 63dcf0ecf4
commit 57d27480ae
12 changed files with 142 additions and 50 deletions

View File

@@ -14,14 +14,14 @@ Contract Queue Job
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github .. |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 :alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/110/12.0 :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/contract&target_branch=14.0
:alt: Try me on Runbot :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |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:: .. contents::
:local: :local:
Usage
=====
The feature can be enabled by setting the ir.config_parameter
"contract.queue.job" to True.
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_queue_job%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_queue_job%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. 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 .. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px
:target: https://github.com/sbejaoui :target: https://github.com/sbejaoui
:alt: sbejaoui :alt: sbejaoui
.. |maintainer-BurkhalterY| image:: https://github.com/BurkhalterY.png?size=40px
:target: https://github.com/BurkhalterY
:alt: BurkhalterY
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-sbejaoui| |maintainer-sbejaoui| |maintainer-BurkhalterY|
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/12.0/contract_queue_job>`_ project on GitHub. This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/14.0/contract_queue_job>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

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

View File

@@ -6,10 +6,14 @@
"summary": """ "summary": """
This addon make contract invoicing cron plan each contract in a job This addon make contract invoicing cron plan each contract in a job
instead of creating all invoices in one transaction""", instead of creating all invoices in one transaction""",
"version": "12.0.1.1.0", "version": "14.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)", "author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract", "website": "https://github.com/OCA/contract",
"depends": ["contract", "queue_job"], "depends": ["contract", "queue_job"],
"maintainers": ["sbejaoui"], "data": [
"data/ir_config_parameter.xml",
"wizards/contract_manually_create_invoice.xml",
],
"maintainers": ["sbejaoui", "BurkhalterY"],
} }

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="config_param_contract_queue_job_as_job" model="ir.config_parameter">
<field name="key">contract.queue.job</field>
<!-- keep key creation with False to avoid test conflicts -->
<field name="value">False</field>
</record>
</odoo>

View File

@@ -1,23 +1,28 @@
# Copyright 2020 ACSONE SA/NV # Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast
from odoo import api, models from odoo import models
from odoo.addons.queue_job.job import job
QUEUE_CHANNEL = "root.CONTRACT_INVOICE"
class ContractContract(models.Model): class ContractContract(models.Model):
_inherit = "contract.contract" _inherit = "contract.contract"
@api.multi
@job(default_channel=QUEUE_CHANNEL)
def _recurring_create_invoice(self, date_ref=False): def _recurring_create_invoice(self, date_ref=False):
res = self.env["account.invoice"] as_job = (
if len(self) > 1: 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: for rec in self:
rec.with_delay()._recurring_create_invoice(date_ref=date_ref) 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) return super()._recurring_create_invoice(date_ref=date_ref)

View File

@@ -1,20 +1,27 @@
# Copyright 2021 ACSONE SA/NV # Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast
from odoo import models from odoo import models
from odoo.addons.queue_job.job import job
QUEUE_CHANNEL = "root.CONTRACT_LINE_RENEW"
class ContractLine(models.Model): class ContractLine(models.Model):
_inherit = "contract.line" _inherit = "contract.line"
@job(default_channel=QUEUE_CHANNEL)
def renew(self): 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: for rec in self:
rec.with_delay().renew() rec.with_delay().renew()
return self.env["contract.line"] return self.env["contract.line"]

View File

@@ -0,0 +1,2 @@
The feature can be enabled by setting the ir.config_parameter
"contract.queue.job" to True.

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Contract Queue Job</title> <title>Contract Queue Job</title>
<style type="text/css"> <style type="text/css">
@@ -367,52 +367,58 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/12.0/contract_queue_job"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-contract_queue_job"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/110/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/contract_queue_job"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-contract_queue_job"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/contract&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction</p> <p>This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li> <li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul> <li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li> <li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li> <li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li> <li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>The feature can be enabled by setting the ir.config_parameter
“contract.queue.job” to True.</p>
</div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_queue_job%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_queue_job%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
<h1><a class="toc-backref" href="#id2">Credits</a></h1> <h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors"> <div class="section" id="authors">
<h2><a class="toc-backref" href="#id3">Authors</a></h2> <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>ACSONE SA/NV</li> <li>ACSONE SA/NV</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2> <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Souheil Bejaoui &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li> <li>Souheil Bejaoui &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2> <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p> <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/sbejaoui"><img alt="sbejaoui" src="https://github.com/sbejaoui.png?size=40px" /></a></p> <p><a class="reference external" href="https://github.com/sbejaoui"><img alt="sbejaoui" src="https://github.com/sbejaoui.png?size=40px" /></a> <a class="reference external" href="https://github.com/BurkhalterY"><img alt="BurkhalterY" src="https://github.com/BurkhalterY.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/12.0/contract_queue_job">OCA/contract</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/contract_queue_job">OCA/contract</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,8 @@
# Copyright 2020 ACSONE SA/NV # Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import fields from odoo import fields
from odoo.addons.contract.tests.test_contract import TestContractBase from odoo.addons.contract.tests.test_contract import TestContractBase
@@ -11,6 +13,7 @@ class TestContractLineQueueJob(TestContractBase, JobMixin):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestContractLineQueueJob, cls).setUpClass() super(TestContractLineQueueJob, cls).setUpClass()
cls.env["ir.config_parameter"].sudo().set_param("contract.queue.job", True)
cls.contract3 = cls.contract2.copy() cls.contract3 = cls.contract2.copy()
def test_contract_renew_queue_job_1(self): def test_contract_renew_queue_job_1(self):
@@ -27,3 +30,21 @@ class TestContractLineQueueJob(TestContractBase, JobMixin):
job_counter = self.job_counter() job_counter = self.job_counter()
lines.renew() lines.renew()
self.assertEqual(job_counter.count_created(), len(lines)) self.assertEqual(job_counter.count_created(), len(lines))
def test_contract_renew_queue_job_3(self):
"""wrong ir_config_parameter : no job"""
self.env["ir.config_parameter"].sudo().set_param(
"contract.queue.job", "wronginput"
)
date_start = self.today - relativedelta(months=9)
self.acct_line.write(
{
"date_start": date_start,
"recurring_next_date": date_start,
"date_end": self.today,
}
)
lines = self.acct_line | self.acct_line.copy()
job_counter = self.job_counter()
lines.renew()
self.assertEqual(job_counter.count_created(), 0)

View File

@@ -9,11 +9,12 @@ class TestContractQueueJob(TestContractBase, JobMixin):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestContractQueueJob, cls).setUpClass() super(TestContractQueueJob, cls).setUpClass()
cls.env["ir.config_parameter"].sudo().set_param("contract.queue.job", True)
cls.contract3 = cls.contract2.copy() cls.contract3 = cls.contract2.copy()
def _get_related_invoices(self, contracts): def _get_related_invoices(self, contracts):
return ( return (
self.env["account.invoice.line"] self.env["account.move.line"]
.search( .search(
[ [
( (
@@ -23,7 +24,7 @@ class TestContractQueueJob(TestContractBase, JobMixin):
) )
] ]
) )
.mapped("invoice_id") .mapped("move_id")
) )
def test_contract_queue_job(self): def test_contract_queue_job(self):
@@ -54,10 +55,20 @@ class TestContractQueueJob(TestContractBase, JobMixin):
wizard = self.env["contract.manually.create.invoice"].create( wizard = self.env["contract.manually.create.invoice"].create(
{"invoice_date": self.today, "contract_type": "purchase"} {"invoice_date": self.today, "contract_type": "purchase"}
) )
wizard.create_invoice() wizard.create_invoice_queued()
invoices = self._get_related_invoices(contracts) invoices = self._get_related_invoices(contracts)
self.assertFalse(invoices) self.assertFalse(invoices)
self.assertEqual(job_counter.count_created(), 2) self.assertEqual(job_counter.count_created(), 2)
self.perform_jobs(job_counter) self.perform_jobs(job_counter)
invoices = self._get_related_invoices(contracts) invoices = self._get_related_invoices(contracts)
self.assertEqual(len(invoices), 2) self.assertEqual(len(invoices), 2)
def test_contract_queue_job_3(self):
"""wrong ir_config_parameter : no job"""
self.env["ir.config_parameter"].sudo().set_param(
"contract.queue.job", "wronginput"
)
contracts = self.contract2 | self.contract3
job_counter = self.job_counter()
contracts._recurring_create_invoice()
self.assertEqual(job_counter.count_created(), 0)

View File

@@ -1,15 +1,14 @@
# Copyright 2020 ACSONE SA/NV # Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models from odoo import models
class ContractManuallyCreateInvoice(models.TransientModel): class ContractManuallyCreateInvoice(models.TransientModel):
_inherit = "contract.manually.create.invoice" _inherit = "contract.manually.create.invoice"
@api.multi def create_invoice_queued(self):
def create_invoice(self):
self.ensure_one() self.ensure_one()
self.contract_to_invoice_ids._recurring_create_invoice() self.contract_to_invoice_ids._recurring_create_invoice()
return {} return {}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="contract_manually_create_invoice_form_view" model="ir.ui.view">
<field name="model">contract.manually.create.invoice</field>
<field
name="inherit_id"
ref="contract.contract_manually_create_invoice_form_view"
/>
<field name="arch" type="xml">
<xpath expr="//button[@name='create_invoice']" position="after">
<button
name="create_invoice_queued"
attrs="{'invisible': [('contract_to_invoice_count', '=', 0)]}"
string="Enqueue invoices creation"
class="btn-primary"
type="object"
/>
</xpath>
</field>
</record>
</odoo>