-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix implementation of related actions
- Loading branch information
Showing
8 changed files
with
102 additions
and
108 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
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 |
---|---|---|
@@ -1,24 +1 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from contextlib import contextmanager | ||
from odoo.addons.queue_job.job import related_action | ||
|
||
|
||
def start_related_actionify(method, **kwargs): | ||
related_action(**kwargs)(method) | ||
|
||
|
||
def stop_related_actionify(method): | ||
attrs = ('related_action',) | ||
for attr in attrs: | ||
if hasattr(method.__func__, attr): | ||
delattr(method.__func__, attr) | ||
|
||
|
||
@contextmanager | ||
def related_actionify(method, **kwargs): | ||
try: | ||
start_related_actionify(method, **kwargs) | ||
yield | ||
finally: | ||
stop_related_actionify(method) |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_test_queue_job,access_test_queue_job,model_test_queue_job,,1,1,1,1 | ||
access_test_queue_channel,access_test_queue_channel,model_test_queue_channel,,1,1,1,1 | ||
access_test_related_action,access_test_related_action,model_test_related_action,,1,1,1,1 |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import test_job | ||
from . import test_job_channels | ||
from . import test_related_actions |
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,46 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2014-2016 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import odoo.tests.common as common | ||
from odoo.addons.queue_job.job import Job | ||
|
||
|
||
class TestRelatedAction(common.TransactionCase): | ||
""" Test Related Actions """ | ||
|
||
def setUp(self): | ||
super(TestRelatedAction, self).setUp() | ||
self.model = self.env['test.related.action'] | ||
self.method = self.env['queue.job'].testing_method | ||
|
||
def test_no_related_action(self): | ||
""" Job without related action """ | ||
job = Job(self.model.testing_related_action__no) | ||
self.assertIsNone(job.related_action()) | ||
|
||
def test_return_none(self): | ||
""" Job with related action returning None """ | ||
# default action returns None | ||
job = Job(self.model.testing_related_action__return_none) | ||
self.assertIsNone(job.related_action()) | ||
|
||
def test_kwargs(self): | ||
""" Job with related action check if action propagates kwargs """ | ||
job_ = Job(self.model.testing_related_action__kwargs) | ||
self.assertEqual(job_.related_action(), (job_.db_record(), {'b': 4})) | ||
|
||
def test_store_related_action(self): | ||
""" Call the related action on the model """ | ||
job = Job(self.model.testing_related_action__store, | ||
args=('Discworld',)) | ||
job.store() | ||
stored_job = self.env['queue.job'].search( | ||
[('uuid', '=', job.uuid)] | ||
) | ||
self.assertEqual(len(stored_job), 1) | ||
expected = {'type': 'ir.actions.act_url', | ||
'target': 'new', | ||
'url': 'https://en.wikipedia.org/wiki/Discworld', | ||
} | ||
self.assertEquals(stored_job.open_related_action(), expected) |