forked from OCA/ddmrp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It makes calls to "cron_actions" run in queue jobs. The jobs have an identity key with "identity_exact", meaning that only one occurence of a job for the same buffer with the same arguments (only_nfp) will be created at a time (e.g. when the state of a stock.move is changed several times in the same transaction or in a different transaction in a short timeframe). It needs OCA/queue#274 and OCA/queue#275
- Loading branch information
Showing
14 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 id="job_function_stock_buffer_cron_actions" model="queue.job.function"> | ||
<field name="name"><![CDATA[<stock.buffer>.cron_actions]]></field> | ||
<field name="channel_id" ref="channel_ddmrp" /> | ||
</record> | ||
</odoo> |
This file contains 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 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,31 @@ | ||
# 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 _register_hook(self): | ||
self._patch_method( | ||
"cron_actions", | ||
self._patch_job_auto_delay( | ||
"cron_actions", context_key="auto_delay_ddmrp_cron_actions" | ||
), | ||
) | ||
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) |
This file contains 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 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 <[email protected]> |
This file contains 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,5 @@ | ||
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. |
This file contains 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 |
31 changes: 31 additions & 0 deletions
31
ddmrp_cron_actions_as_job/tests/test_cron_actions_as_job.py
This file contains 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,31 @@ | ||
# Copyright 2020 Camptocamp (https://www.camptocamp.com) | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
|
||
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 | ||
|
||
|
||
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}) |
1 change: 1 addition & 0 deletions
1
setup/ddmrp_cron_actions_as_job/odoo/addons/ddmrp_cron_actions_as_job
This file contains 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 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, | ||
) |