-
-
Notifications
You must be signed in to change notification settings - Fork 114
[13.0] Add ddmrp_cron_actions_as_job #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f6b7ef8
Add ddmrp_cron_actions_as_job
8123cb4
use split_every in buffer crons in order to allow more frequent
JordiBForgeFlow c4ae03e
commit only if we are not testing
JordiBForgeFlow c555bdc
Fix fetching issue on crons methods
92ae390
Invalidate computed non-stored fields in cron_actions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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": "13.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, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <odoo noupdate="1"> | ||
| <record model="queue.job.channel" id="channel_ddmrp"> | ||
| <field name="name">ddmrp</field> | ||
| <field name="parent_id" ref="queue_job.channel_root" /> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <odoo noupdate="1"> | ||
| <record id="job_function_stock_buffer_cron_actions" model="queue.job.function"> | ||
| <field name="model_id" ref="ddmrp.model_stock_buffer" /> | ||
| <field name="method">cron_actions</field> | ||
| <field name="channel_id" ref="channel_ddmrp" /> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import stock_buffer | ||
| from . import stock_move |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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": "DDMRP Buffer calculation ({})".format(self.display_name), | ||
| } | ||
|
|
||
| def _calc_adu_job_options(self): | ||
| return { | ||
| "identity_key": identity_exact, | ||
| "priority": 15, | ||
| "description": "DDMRP Buffer ADU calculation ({})".format( | ||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Guewen Baconnier <guewen.baconnier@camptocamp.com> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ``<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``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import test_cron_actions_as_job |
56 changes: 56 additions & 0 deletions
56
ddmrp_cron_actions_as_job/tests/test_cron_actions_as_job.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # 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) | ||
| del context["test_queue_job_no_delay"] | ||
| 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) | ||
| del context["test_queue_job_no_delay"] | ||
| 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, {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ stock-logistics-warehouse | |
| web | ||
| manufacture | ||
| server-tools | ||
| queue | ||
1 change: 1 addition & 0 deletions
1
setup/ddmrp_cron_actions_as_job/odoo/addons/ddmrp_cron_actions_as_job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../ddmrp_cron_actions_as_job |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import setuptools | ||
|
|
||
| setuptools.setup( | ||
| setup_requires=['setuptools-odoo'], | ||
| odoo_addon=True, | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.