diff --git a/ddmrp_warning_as_job/README.rst b/ddmrp_warning_as_job/README.rst new file mode 100644 index 000000000..9cc482d2a --- /dev/null +++ b/ddmrp_warning_as_job/README.rst @@ -0,0 +1,84 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +==================== +DDMRP Warning as job +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f4fd5dfb7590158816c019119a1932be3c25521fa8cafaa44d8e9df3ffede929 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/ddmrp_warning_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-19-0/ddmrp-19-0-ddmrp_warning_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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +DDMRP Warning calculations are now run with Queue Jobs. + +The ``._generate_ddmrp_warnings`` method is automatically +delayed when the context contains +``auto_delay_ddmrp_generate_ddmrp_warnings=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 +------- + +* ForgeFlow + +Contributors +------------ + +David Jiménez david.jimenez@forgeflow.com + +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_warning_as_job/__init__.py b/ddmrp_warning_as_job/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/ddmrp_warning_as_job/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/ddmrp_warning_as_job/__manifest__.py b/ddmrp_warning_as_job/__manifest__.py new file mode 100644 index 000000000..6e4236450 --- /dev/null +++ b/ddmrp_warning_as_job/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 ForgeFlow (https://www.camptocamp.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "DDMRP Warning as job", + "version": "19.0.1.0.0", + "summary": "Run DDMRP Warning as jobs", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/ddmrp", + "category": "Warehouse Management", + "depends": ["ddmrp_warning", "ddmrp_cron_actions_as_job"], + "data": ["data/queue_job_function_data.xml"], + "license": "LGPL-3", + "installable": True, +} diff --git a/ddmrp_warning_as_job/data/queue_job_function_data.xml b/ddmrp_warning_as_job/data/queue_job_function_data.xml new file mode 100644 index 000000000..c326bd1b7 --- /dev/null +++ b/ddmrp_warning_as_job/data/queue_job_function_data.xml @@ -0,0 +1,10 @@ + + + + + + _generate_ddmrp_warnings + + + diff --git a/ddmrp_warning_as_job/i18n/it.po b/ddmrp_warning_as_job/i18n/it.po new file mode 100644 index 000000000..fa41a6cf2 --- /dev/null +++ b/ddmrp_warning_as_job/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * ddmrp_warning_as_job +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-11-11 14:06+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 5.6.2\n" + +#. module: ddmrp_warning_as_job +#: model:ir.model,name:ddmrp_warning_as_job.model_stock_buffer +msgid "Stock Buffer" +msgstr "Buffer di materiale" diff --git a/ddmrp_warning_as_job/models/__init__.py b/ddmrp_warning_as_job/models/__init__.py new file mode 100644 index 000000000..46f971b6d --- /dev/null +++ b/ddmrp_warning_as_job/models/__init__.py @@ -0,0 +1 @@ +from . import stock_buffer diff --git a/ddmrp_warning_as_job/models/stock_buffer.py b/ddmrp_warning_as_job/models/stock_buffer.py new file mode 100644 index 000000000..10b61f1df --- /dev/null +++ b/ddmrp_warning_as_job/models/stock_buffer.py @@ -0,0 +1,35 @@ +# Copyright 2024 ForgeFlow (https://www.camptocamp.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +import functools + +from odoo import models + +from odoo.addons.queue_job.job import identity_exact + + +class Buffer(models.Model): + _inherit = "stock.buffer" + + def _generate_ddmrp_warnings_job_options(self): + return { + "identity_key": identity_exact, + "priority": 15, + "description": f"DDMRP Warning calculation ({self.display_name})", + } + + def _register_hook(self): + patched = self._patch_job_auto_delay( + "_generate_ddmrp_warnings", + context_key="auto_delay_ddmrp_generate_ddmrp_warnings", + ) + cls = type(self) + cls._generate_ddmrp_warnings = functools.update_wrapper( + patched, cls._generate_ddmrp_warnings + ) + return super()._register_hook() + + def cron_generate_ddmrp_warnings(self, automatic=False): + return super( + Buffer, self.with_context(auto_delay_ddmrp_generate_ddmrp_warnings=True) + ).cron_generate_ddmrp_warnings(automatic=automatic) diff --git a/ddmrp_warning_as_job/pyproject.toml b/ddmrp_warning_as_job/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/ddmrp_warning_as_job/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/ddmrp_warning_as_job/readme/CONTRIBUTORS.md b/ddmrp_warning_as_job/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..7cf8d69ff --- /dev/null +++ b/ddmrp_warning_as_job/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +David Jiménez diff --git a/ddmrp_warning_as_job/readme/DESCRIPTION.md b/ddmrp_warning_as_job/readme/DESCRIPTION.md new file mode 100644 index 000000000..c098fad82 --- /dev/null +++ b/ddmrp_warning_as_job/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +DDMRP Warning calculations are now run with Queue Jobs. + +The `._generate_ddmrp_warnings` method is automatically delayed when +the context contains `auto_delay_ddmrp_generate_ddmrp_warnings=True`. + diff --git a/ddmrp_warning_as_job/static/description/icon.png b/ddmrp_warning_as_job/static/description/icon.png new file mode 100644 index 000000000..90c92e98d Binary files /dev/null and b/ddmrp_warning_as_job/static/description/icon.png differ diff --git a/ddmrp_warning_as_job/static/description/index.html b/ddmrp_warning_as_job/static/description/index.html new file mode 100644 index 000000000..b36aae71f --- /dev/null +++ b/ddmrp_warning_as_job/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

DDMRP Warning as job

+ +

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

+

DDMRP Warning calculations are now run with Queue Jobs.

+

The <stock.buffer>._generate_ddmrp_warnings method is automatically +delayed when the context contains +auto_delay_ddmrp_generate_ddmrp_warnings=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

+
    +
  • ForgeFlow
  • +
+
+ +
+

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_warning_as_job/tests/__init__.py b/ddmrp_warning_as_job/tests/__init__.py new file mode 100644 index 000000000..89479b42d --- /dev/null +++ b/ddmrp_warning_as_job/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ddmrp_warning_as_job diff --git a/ddmrp_warning_as_job/tests/test_ddmrp_warning_as_job.py b/ddmrp_warning_as_job/tests/test_ddmrp_warning_as_job.py new file mode 100644 index 000000000..084d8b2dc --- /dev/null +++ b/ddmrp_warning_as_job/tests/test_ddmrp_warning_as_job.py @@ -0,0 +1,37 @@ +# Copyright 2024 ForgeFlow (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 TestDdmrpWarningAsJob(TestDdmrpCommon): + def test_generate_ddmrp_warnings_delay_job(self): + context = dict(self.env.context, auto_delay_ddmrp_generate_ddmrp_warnings=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._generate_ddmrp_warnings() + + # 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 '_generate_ddmrp_warnings' + self.assertEqual(delayable._generate_ddmrp_warnings.call_count, 1) + delay_args, delay_kwargs = delayable._generate_ddmrp_warnings.call_args + self.assertEqual(delay_args, ()) + self.assertDictEqual(delay_kwargs, {}) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..f0b9099d7 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,4 @@ +# DO NOT MERGE — temporary pins until the ddmrp_warning and +# ddmrp_cron_actions_as_job 19.0 MIGs land. +odoo-addon-ddmrp_warning @ git+https://github.com/ledoent/ddmrp.git@19.0-mig-ddmrp_warning#subdirectory=ddmrp_warning +odoo-addon-ddmrp_cron_actions_as_job @ git+https://github.com/ledoent/ddmrp.git@19.0-mig-ddmrp_cron_actions_as_job#subdirectory=ddmrp_cron_actions_as_job