diff --git a/contract_invoice_auto_validate/README.rst b/contract_invoice_auto_validate/README.rst new file mode 100644 index 000000000..828c923c8 --- /dev/null +++ b/contract_invoice_auto_validate/README.rst @@ -0,0 +1,85 @@ +============================== +Contract Invoice Auto Validate +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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 + :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_invoice_auto_validate + :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_invoice_auto_validate + :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 + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon auto-validate invoices after its creation from a contract + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Before installing this addon make sur that "CONTRACT_INVOICE" queue channel has +at maximum a capacity=1 in the odoo configuration file. Otherwise you will have +concurrency access issue between jobs to the account.move sequence. + +Example: + +[queue_job] +channels=root:5,root.CONTRACT_INVOICE:1 + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/contract `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/contract_invoice_auto_validate/__init__.py b/contract_invoice_auto_validate/__init__.py new file mode 100644 index 000000000..0ee8b5073 --- /dev/null +++ b/contract_invoice_auto_validate/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/contract_invoice_auto_validate/__manifest__.py b/contract_invoice_auto_validate/__manifest__.py new file mode 100644 index 000000000..a636c42e3 --- /dev/null +++ b/contract_invoice_auto_validate/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Invoice Auto Validate", + "summary": """ + This addon auto-validate invoices after its creation from a contract + """, + "version": "12.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"], +} diff --git a/contract_invoice_auto_validate/models/__init__.py b/contract_invoice_auto_validate/models/__init__.py new file mode 100644 index 000000000..acc8a06b7 --- /dev/null +++ b/contract_invoice_auto_validate/models/__init__.py @@ -0,0 +1 @@ +from . import contract_contract diff --git a/contract_invoice_auto_validate/models/contract_contract.py b/contract_invoice_auto_validate/models/contract_contract.py new file mode 100644 index 000000000..b10797235 --- /dev/null +++ b/contract_invoice_auto_validate/models/contract_contract.py @@ -0,0 +1,14 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ContractContract(models.Model): + + _inherit = "contract.contract" + + def _finalize_and_create_invoices(self, invoices_values): + invoices = super()._finalize_and_create_invoices(invoices_values) + invoices.filtered("invoice_line_ids").action_invoice_open() + return invoices diff --git a/contract_invoice_auto_validate/readme/CONTRIBUTORS.rst b/contract_invoice_auto_validate/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..50e6298db --- /dev/null +++ b/contract_invoice_auto_validate/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/contract_invoice_auto_validate/readme/DESCRIPTION.rst b/contract_invoice_auto_validate/readme/DESCRIPTION.rst new file mode 100644 index 000000000..7ffeea9a4 --- /dev/null +++ b/contract_invoice_auto_validate/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This addon auto-validate invoices after its creation from a contract diff --git a/contract_invoice_auto_validate/readme/USAGE.rst b/contract_invoice_auto_validate/readme/USAGE.rst new file mode 100644 index 000000000..f58ac5bd6 --- /dev/null +++ b/contract_invoice_auto_validate/readme/USAGE.rst @@ -0,0 +1,8 @@ +Before installing this addon make sur that "CONTRACT_INVOICE" queue channel has +at maximum a capacity=1 in the odoo configuration file. Otherwise you will have +concurrency access issue between jobs to the account.move sequence. + +Example: + +[queue_job] +channels=root:5,root.CONTRACT_INVOICE:1 \ No newline at end of file diff --git a/contract_invoice_auto_validate/static/description/icon.png b/contract_invoice_auto_validate/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/contract_invoice_auto_validate/static/description/icon.png differ diff --git a/contract_invoice_auto_validate/static/description/index.html b/contract_invoice_auto_validate/static/description/index.html new file mode 100644 index 000000000..2b9a8b227 --- /dev/null +++ b/contract_invoice_auto_validate/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Contract Invoice Auto Validate + + + +
+

Contract Invoice Auto Validate

+ + +

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

+

This addon auto-validate invoices after its creation from a contract

+

Table of contents

+ +
+

Usage

+

Before installing this addon make sur that “CONTRACT_INVOICE” queue channel has +at maximum a capacity=1 in the odoo configuration file. Otherwise you will have +concurrency access issue between jobs to the account.move sequence.

+

Example:

+

[queue_job] +channels=root:5,root.CONTRACT_INVOICE:1

+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/contract project on GitHub.

+

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

+
+
+
+ + diff --git a/contract_invoice_auto_validate/tests/__init__.py b/contract_invoice_auto_validate/tests/__init__.py new file mode 100644 index 000000000..57d821499 --- /dev/null +++ b/contract_invoice_auto_validate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract_invoice_auto_validate diff --git a/contract_invoice_auto_validate/tests/test_contract_invoice_auto_validate.py b/contract_invoice_auto_validate/tests/test_contract_invoice_auto_validate.py new file mode 100644 index 000000000..f51632442 --- /dev/null +++ b/contract_invoice_auto_validate/tests/test_contract_invoice_auto_validate.py @@ -0,0 +1,32 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase +from odoo.addons.queue_job.tests.common import JobMixin + + +class TestContractAutoValidate(TestContractBase, JobMixin): + @classmethod + def setUpClass(cls): + super(TestContractAutoValidate, cls).setUpClass() + cls.contract3 = cls.contract2.copy() + + def _get_related_invoices(self, contracts): + return ( + self.env['account.invoice.line'] + .search( + [ + ( + 'contract_line_id', + 'in', + contracts.mapped('contract_line_ids.id'), + ) + ] + ) + .mapped('invoice_id') + ) + + def test_contract_invoice_auto_validate(self): + contracts = self.contract2 + invoice = contracts._recurring_create_invoice() + self.assertEqual(invoice.state, 'open') diff --git a/contract_queue_job/README.rst b/contract_queue_job/README.rst new file mode 100644 index 000000000..90709f75a --- /dev/null +++ b/contract_queue_job/README.rst @@ -0,0 +1,73 @@ +================== +Contract Queue Job +================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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 + :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 + :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 + :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 + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/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 new file mode 100644 index 000000000..1c15bc7ee --- /dev/null +++ b/contract_queue_job/__init__.py @@ -0,0 +1,3 @@ +from . import models +from . import wizards +from . import tests diff --git a/contract_queue_job/__manifest__.py b/contract_queue_job/__manifest__.py new file mode 100644 index 000000000..3bdf62358 --- /dev/null +++ b/contract_queue_job/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Queue Job", + "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.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"], +} diff --git a/contract_queue_job/models/__init__.py b/contract_queue_job/models/__init__.py new file mode 100644 index 000000000..acc8a06b7 --- /dev/null +++ b/contract_queue_job/models/__init__.py @@ -0,0 +1 @@ +from . import contract_contract diff --git a/contract_queue_job/models/contract_contract.py b/contract_queue_job/models/contract_contract.py new file mode 100644 index 000000000..fe81e3ef6 --- /dev/null +++ b/contract_queue_job/models/contract_contract.py @@ -0,0 +1,22 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models +from odoo.addons.queue_job.job import job + +QUEUE_CHANNEL = "root.CONTRACT_INVOICE" + + +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: + for rec in self: + rec.with_delay()._recurring_create_invoice(date_ref=date_ref) + return res + return super()._recurring_create_invoice(date_ref=date_ref) diff --git a/contract_queue_job/readme/CONTRIBUTORS.rst b/contract_queue_job/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..50e6298db --- /dev/null +++ b/contract_queue_job/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/contract_queue_job/readme/DESCRIPTION.rst b/contract_queue_job/readme/DESCRIPTION.rst new file mode 100644 index 000000000..150a27af8 --- /dev/null +++ b/contract_queue_job/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction diff --git a/contract_queue_job/static/description/icon.png b/contract_queue_job/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/contract_queue_job/static/description/icon.png differ diff --git a/contract_queue_job/static/description/index.html b/contract_queue_job/static/description/index.html new file mode 100644 index 000000000..784dd6055 --- /dev/null +++ b/contract_queue_job/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Contract Queue Job + + + +
+

Contract Queue Job

+ + +

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

+

This addon make contract invoicing cron plan each contract in a job instead of creating all invoices in one transaction

+

Table of contents

+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/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/tests/__init__.py b/contract_queue_job/tests/__init__.py new file mode 100644 index 000000000..79c30bada --- /dev/null +++ b/contract_queue_job/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract_queue_job diff --git a/contract_queue_job/tests/test_contract_queue_job.py b/contract_queue_job/tests/test_contract_queue_job.py new file mode 100644 index 000000000..ad30beeff --- /dev/null +++ b/contract_queue_job/tests/test_contract_queue_job.py @@ -0,0 +1,63 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase +from odoo.addons.queue_job.tests.common import JobMixin + + +class TestContractQueueJob(TestContractBase, JobMixin): + @classmethod + def setUpClass(cls): + super(TestContractQueueJob, cls).setUpClass() + cls.contract3 = cls.contract2.copy() + + def _get_related_invoices(self, contracts): + return ( + self.env["account.invoice.line"] + .search( + [ + ( + "contract_line_id", + "in", + contracts.mapped("contract_line_ids.id"), + ) + ] + ) + .mapped("invoice_id") + ) + + def test_contract_queue_job(self): + contracts = self.contract2 | self.contract3 + job_counter = self.job_counter() + invoices = contracts._recurring_create_invoice() + self.assertFalse(invoices) + invoices = self._get_related_invoices(contracts) + self.assertFalse(invoices) + self.assertEqual(job_counter.count_created(), 2) + self.perform_jobs(job_counter) + invoices = self._get_related_invoices(contracts) + self.assertEqual(len(invoices), 2) + + def test_contract_queue_job_1(self): + contracts = self.contract2 + job_counter = self.job_counter() + count_all_jobs = job_counter.count_all() + self.assertEqual(job_counter.count_all(), count_all_jobs) + invoices_res = contracts._recurring_create_invoice() + self.assertTrue(invoices_res) + invoices = self._get_related_invoices(contracts) + self.assertEqual(invoices_res, invoices) + + def test_contract_queue_job_2(self): + contracts = self.contract2 | self.contract3 + job_counter = self.job_counter() + wizard = self.env["contract.manually.create.invoice"].create( + {"invoice_date": self.today, "contract_type": "purchase"} + ) + wizard.create_invoice() + invoices = self._get_related_invoices(contracts) + self.assertFalse(invoices) + self.assertEqual(job_counter.count_created(), 2) + self.perform_jobs(job_counter) + invoices = self._get_related_invoices(contracts) + self.assertEqual(len(invoices), 2) diff --git a/contract_queue_job/wizards/__init__.py b/contract_queue_job/wizards/__init__.py new file mode 100644 index 000000000..2e56cd6d0 --- /dev/null +++ b/contract_queue_job/wizards/__init__.py @@ -0,0 +1 @@ +from . import contract_manually_create_invoice diff --git a/contract_queue_job/wizards/contract_manually_create_invoice.py b/contract_queue_job/wizards/contract_manually_create_invoice.py new file mode 100644 index 000000000..98b5d3593 --- /dev/null +++ b/contract_queue_job/wizards/contract_manually_create_invoice.py @@ -0,0 +1,15 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ContractManuallyCreateInvoice(models.TransientModel): + + _inherit = "contract.manually.create.invoice" + + @api.multi + def create_invoice(self): + self.ensure_one() + self.contract_to_invoice_ids._recurring_create_invoice() + return {}