diff --git a/ddmrp_cron_actions_as_job/README.rst b/ddmrp_cron_actions_as_job/README.rst new file mode 100644 index 000000000..72c96181e --- /dev/null +++ b/ddmrp_cron_actions_as_job/README.rst @@ -0,0 +1,89 @@ +=============================== +DDMRP Buffer Calculation as job +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9e8a8dbcb18721e0b5be9ff3418bc0ddd61cc848b94134281a95f90cd2d690ad + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fddmrp-lightgray.png?logo=github + :target: https://github.com/OCA/ddmrp/tree/17.0/ddmrp_cron_actions_as_job + :alt: OCA/ddmrp +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/ddmrp-17-0/ddmrp-17-0-ddmrp_cron_actions_as_job + :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/ddmrp&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +DDMRP Buffer calculations are now run with Queue Jobs. + +When auto-update of NFP is active, each time the state of a stock move +changes, a new computation is triggered, but thanks to identity keys on +jobs, only one job at a time is generated for the same buffer. + +The ``.cron_actions`` method is automatically delayed when +the context contains ``auto_delay_ddmrp_cron_actions=True``. + +The scheduled action for buffers ADU computation also generates jobs +instead of recomputing all the buffers at once. + +The ``._calc_adu`` method is automatically delayed when +the context contains ``auto_delay_ddmrp_calc_adu=True``. + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Guewen Baconnier + +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/ddmrp `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/ddmrp_cron_actions_as_job/__init__.py b/ddmrp_cron_actions_as_job/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/ddmrp_cron_actions_as_job/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/ddmrp_cron_actions_as_job/__manifest__.py b/ddmrp_cron_actions_as_job/__manifest__.py new file mode 100644 index 000000000..4995bd9f8 --- /dev/null +++ b/ddmrp_cron_actions_as_job/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Camptocamp (https://www.camptocamp.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "DDMRP Buffer Calculation as job", + "version": "17.0.1.0.0", + "summary": "Run DDMRP Buffer Calculation as jobs", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/ddmrp", + "category": "Warehouse Management", + "depends": ["ddmrp", "queue_job"], + "data": ["data/queue_job_channel_data.xml", "data/queue_job_function_data.xml"], + "license": "LGPL-3", + "installable": True, +} diff --git a/ddmrp_cron_actions_as_job/data/queue_job_channel_data.xml b/ddmrp_cron_actions_as_job/data/queue_job_channel_data.xml new file mode 100644 index 000000000..b3053db8e --- /dev/null +++ b/ddmrp_cron_actions_as_job/data/queue_job_channel_data.xml @@ -0,0 +1,6 @@ + + + ddmrp + + + diff --git a/ddmrp_cron_actions_as_job/data/queue_job_function_data.xml b/ddmrp_cron_actions_as_job/data/queue_job_function_data.xml new file mode 100644 index 000000000..610831645 --- /dev/null +++ b/ddmrp_cron_actions_as_job/data/queue_job_function_data.xml @@ -0,0 +1,12 @@ + + + + cron_actions + + + + + _calc_adu + + + diff --git a/ddmrp_cron_actions_as_job/i18n/ddmrp_cron_actions_as_job.pot b/ddmrp_cron_actions_as_job/i18n/ddmrp_cron_actions_as_job.pot new file mode 100644 index 000000000..bfa8eeff5 --- /dev/null +++ b/ddmrp_cron_actions_as_job/i18n/ddmrp_cron_actions_as_job.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ddmrp_cron_actions_as_job +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_buffer +msgid "Stock Buffer" +msgstr "" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_move +msgid "Stock Move" +msgstr "" diff --git a/ddmrp_cron_actions_as_job/i18n/es.po b/ddmrp_cron_actions_as_job/i18n/es.po new file mode 100644 index 000000000..115d5184a --- /dev/null +++ b/ddmrp_cron_actions_as_job/i18n/es.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ddmrp_cron_actions_as_job +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-28 21:33+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_buffer +msgid "Stock Buffer" +msgstr "Amortiguador de Inventario" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de Existencias" diff --git a/ddmrp_cron_actions_as_job/i18n/it.po b/ddmrp_cron_actions_as_job/i18n/it.po new file mode 100644 index 000000000..3bec12842 --- /dev/null +++ b/ddmrp_cron_actions_as_job/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ddmrp_cron_actions_as_job +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-28 20:10+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_buffer +msgid "Stock Buffer" +msgstr "Buffer di materiale" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" diff --git a/ddmrp_cron_actions_as_job/i18n/pt_BR.po b/ddmrp_cron_actions_as_job/i18n/pt_BR.po new file mode 100644 index 000000000..eae4159b3 --- /dev/null +++ b/ddmrp_cron_actions_as_job/i18n/pt_BR.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ddmrp_cron_actions_as_job +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-05-21 03:17+0000\n" +"Last-Translator: Rodrigo Macedo \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_buffer +msgid "Stock Buffer" +msgstr "Buffer de estoque" + +#. module: ddmrp_cron_actions_as_job +#: model:ir.model,name:ddmrp_cron_actions_as_job.model_stock_move +msgid "Stock Move" +msgstr "Movimento de estoque" diff --git a/ddmrp_cron_actions_as_job/models/__init__.py b/ddmrp_cron_actions_as_job/models/__init__.py new file mode 100644 index 000000000..911aa93ea --- /dev/null +++ b/ddmrp_cron_actions_as_job/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_buffer +from . import stock_move diff --git a/ddmrp_cron_actions_as_job/models/stock_buffer.py b/ddmrp_cron_actions_as_job/models/stock_buffer.py new file mode 100644 index 000000000..62dc57578 --- /dev/null +++ b/ddmrp_cron_actions_as_job/models/stock_buffer.py @@ -0,0 +1,49 @@ +# Copyright 2020 Camptocamp (https://www.camptocamp.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + +from odoo.addons.queue_job.job import identity_exact + + +class Buffer(models.Model): + _inherit = "stock.buffer" + + def cron_actions_job_options(self, only_nfp=False): + return { + "identity_key": identity_exact, + "priority": 15, + "description": f"DDMRP Buffer calculation ({self.display_name})", + } + + def _calc_adu_job_options(self): + return { + "identity_key": identity_exact, + "priority": 15, + "description": f"DDMRP Buffer ADU calculation ({self.display_name})", + } + + def _register_hook(self): + self._patch_method( + "cron_actions", + self._patch_job_auto_delay( + "cron_actions", context_key="auto_delay_ddmrp_cron_actions" + ), + ) + self._patch_method( + "_calc_adu", + self._patch_job_auto_delay( + "_calc_adu", context_key="auto_delay_ddmrp_calc_adu" + ), + ) + return super()._register_hook() + + def cron_ddmrp(self, automatic=False): + return super( + Buffer, self.with_context(auto_delay_ddmrp_cron_actions=True) + ).cron_ddmrp(automatic=automatic) + + def cron_ddmrp_adu(self, automatic=False): + return super( + Buffer, self.with_context(auto_delay_ddmrp_calc_adu=True) + ).cron_ddmrp_adu(automatic=automatic) diff --git a/ddmrp_cron_actions_as_job/models/stock_move.py b/ddmrp_cron_actions_as_job/models/stock_move.py new file mode 100644 index 000000000..01abd2455 --- /dev/null +++ b/ddmrp_cron_actions_as_job/models/stock_move.py @@ -0,0 +1,13 @@ +# Copyright 2020 Camptocamp +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _update_ddmrp_nfp(self): + return super( + StockMove, self.with_context(auto_delay_ddmrp_cron_actions=True) + )._update_ddmrp_nfp() diff --git a/ddmrp_cron_actions_as_job/pyproject.toml b/ddmrp_cron_actions_as_job/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/ddmrp_cron_actions_as_job/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/ddmrp_cron_actions_as_job/readme/CONTRIBUTORS.md b/ddmrp_cron_actions_as_job/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..7f97cd053 --- /dev/null +++ b/ddmrp_cron_actions_as_job/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Guewen Baconnier \<\> diff --git a/ddmrp_cron_actions_as_job/readme/DESCRIPTION.md b/ddmrp_cron_actions_as_job/readme/DESCRIPTION.md new file mode 100644 index 000000000..77babb17c --- /dev/null +++ b/ddmrp_cron_actions_as_job/readme/DESCRIPTION.md @@ -0,0 +1,14 @@ +DDMRP Buffer calculations are now run with Queue Jobs. + +When auto-update of NFP is active, each time the state of a stock move +changes, a new computation is triggered, but thanks to identity keys on +jobs, only one job at a time is generated for the same buffer. + +The `.cron_actions` method is automatically delayed when +the context contains `auto_delay_ddmrp_cron_actions=True`. + +The scheduled action for buffers ADU computation also generates jobs +instead of recomputing all the buffers at once. + +The `._calc_adu` method is automatically delayed when the +context contains `auto_delay_ddmrp_calc_adu=True`. diff --git a/ddmrp_cron_actions_as_job/static/description/icon.png b/ddmrp_cron_actions_as_job/static/description/icon.png new file mode 100644 index 000000000..90c92e98d Binary files /dev/null and b/ddmrp_cron_actions_as_job/static/description/icon.png differ diff --git a/ddmrp_cron_actions_as_job/static/description/index.html b/ddmrp_cron_actions_as_job/static/description/index.html new file mode 100644 index 000000000..9a9024bca --- /dev/null +++ b/ddmrp_cron_actions_as_job/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +DDMRP Buffer Calculation as job + + + +
+

DDMRP Buffer Calculation as job

+ + +

Beta License: LGPL-3 OCA/ddmrp Translate me on Weblate Try me on Runboat

+

DDMRP Buffer calculations are now run with Queue Jobs.

+

When auto-update of NFP is active, each time the state of a stock move +changes, a new computation is triggered, but thanks to identity keys on +jobs, only one job at a time is generated for the same buffer.

+

The <stock.buffer>.cron_actions method is automatically delayed when +the context contains auto_delay_ddmrp_cron_actions=True.

+

The scheduled action for buffers ADU computation also generates jobs +instead of recomputing all the buffers at once.

+

The <stock.buffer>._calc_adu method is automatically delayed when +the context contains auto_delay_ddmrp_calc_adu=True.

+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/ddmrp_cron_actions_as_job/tests/__init__.py b/ddmrp_cron_actions_as_job/tests/__init__.py new file mode 100644 index 000000000..48aece491 --- /dev/null +++ b/ddmrp_cron_actions_as_job/tests/__init__.py @@ -0,0 +1 @@ +from . import test_cron_actions_as_job diff --git a/ddmrp_cron_actions_as_job/tests/test_cron_actions_as_job.py b/ddmrp_cron_actions_as_job/tests/test_cron_actions_as_job.py new file mode 100644 index 000000000..b1e62c885 --- /dev/null +++ b/ddmrp_cron_actions_as_job/tests/test_cron_actions_as_job.py @@ -0,0 +1,64 @@ +# Copyright 2020 Camptocamp (https://www.camptocamp.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + + +from odoo.tests import tagged + +from odoo.addons.ddmrp.tests.common import TestDdmrpCommon +from odoo.addons.queue_job.job import identity_exact +from odoo.addons.queue_job.tests.common import mock_with_delay + + +@tagged("post_install", "-at_install") +class TestDdmrpCronActionsAsJob(TestDdmrpCommon): + def test_cron_actions_delay_job(self): + context = dict(self.env.context, auto_delay_ddmrp_cron_actions=True) + context.update( + { + "test_queue_job_no_delay": False, + } + ) + buffer_a = self.buffer_a.with_context(**context) + + with mock_with_delay() as (delayable_cls, delayable): + buffer_a.cron_actions(only_nfp=True) + + # check 'with_delay()' part: + self.assertEqual(delayable_cls.call_count, 1) + # arguments passed in 'with_delay()' + delay_args, delay_kwargs = delayable_cls.call_args + self.assertEqual(delay_args, (self.buffer_a,)) + self.assertEqual(delay_kwargs.get("priority"), 15) + self.assertEqual(delay_kwargs.get("identity_key"), identity_exact) + + # check what's passed to the job method 'cron_actions' + self.assertEqual(delayable.cron_actions.call_count, 1) + delay_args, delay_kwargs = delayable.cron_actions.call_args + self.assertEqual(delay_args, ()) + self.assertDictEqual(delay_kwargs, {"only_nfp": True}) + + def test_calc_adu_delay_job(self): + context = dict(self.env.context, auto_delay_ddmrp_calc_adu=True) + context.update( + { + "test_queue_job_no_delay": False, + } + ) + buffer_a = self.buffer_a.with_context(**context) + + with mock_with_delay() as (delayable_cls, delayable): + buffer_a._calc_adu() + + # check 'with_delay()' part: + self.assertEqual(delayable_cls.call_count, 1) + # arguments passed in 'with_delay()' + delay_args, delay_kwargs = delayable_cls.call_args + self.assertEqual(delay_args, (self.buffer_a,)) + self.assertEqual(delay_kwargs.get("priority"), 15) + self.assertEqual(delay_kwargs.get("identity_key"), identity_exact) + + # check what's passed to the job method '_calc_adu' + self.assertEqual(delayable._calc_adu.call_count, 1) + delay_args, delay_kwargs = delayable._calc_adu.call_args + self.assertEqual(delay_args, ()) + self.assertDictEqual(delay_kwargs, {})