diff options
| author | Thanh Dodeur <tso@odoo.com> | 2020-10-23 13:04:55 +0000 |
|---|---|---|
| committer | Thanh Dodeur <tso@odoo.com> | 2020-10-26 10:16:10 +0000 |
| commit | ce6f6fb4e04746d28e1b959d50f50a855c7a3049 (patch) | |
| tree | dc138f3ac4a0366a1676b2b802d04de9faac1cd3 | |
| parent | 5e46850072f142fb17b72d8738dc4f1c60e3a786 (diff) | |
[FIX] mail: prevents crash when completing self repeating activities
Before this commit, completing an activity that was automatically
generating new activities was causing a crash as no action is returned
when they are completed.
This commit fixes this issue by handling the case where no action is
returned.
opw-2361674
closes odoo/odoo#60628
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
| -rw-r--r-- | addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover_tests.js | 55 | ||||
| -rw-r--r-- | addons/mail/static/src/models/activity/activity.js | 4 |
2 files changed, 56 insertions, 3 deletions
diff --git a/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover_tests.js b/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover_tests.js index c94a0ad4c14..9f94a5bbef1 100644 --- a/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover_tests.js +++ b/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover_tests.js @@ -7,11 +7,14 @@ const components = { const { afterEach, + afterNextRender, beforeEach, createRootComponent, start, } = require('mail/static/src/utils/test_utils.js'); +const Bus = require('web.Bus'); + QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { QUnit.module('activity_mark_done_popover', {}, function () { @@ -206,6 +209,11 @@ QUnit.test('activity mark done popover mark done with feedback', async function QUnit.test('activity mark done popover mark done and schedule next', async function (assert) { assert.expect(6); + const bus = new Bus(); + bus.on('do-action', null, payload => { + assert.step('activity_action'); + throw new Error("The do-action event should not be triggered when the route doesn't return an action"); + }); await this.start({ async mockRPC(route, args) { if (route === '/web/dataset/call_kw/mail.activity/action_feedback_schedule_next') { @@ -214,7 +222,7 @@ QUnit.test('activity mark done popover mark done and schedule next', async funct assert.strictEqual(args.args[0].length, 1); assert.strictEqual(args.args[0][0], 12); assert.strictEqual(args.kwargs.feedback, 'This task is done'); - return; + return false; } if (route === '/web/dataset/call_kw/mail.activity/unlink') { // 'unlink' on non-existing record raises a server crash @@ -222,6 +230,7 @@ QUnit.test('activity mark done popover mark done and schedule next', async funct } return this._super(...arguments); }, + env: { bus }, }); const activity = this.env.models['mail.activity'].create({ canWrite: true, @@ -234,10 +243,50 @@ QUnit.test('activity mark done popover mark done and schedule next', async funct let feedbackTextarea = document.querySelector('.o_ActivityMarkDonePopover_feedback'); feedbackTextarea.focus(); document.execCommand('insertText', false, 'This task is done'); - document.querySelector('.o_ActivityMarkDonePopover_doneScheduleNextButton').click(); + await afterNextRender(() => { + document.querySelector('.o_ActivityMarkDonePopover_doneScheduleNextButton').click(); + }); assert.verifySteps( ['action_feedback_schedule_next'], - "Mark done and schedule next button should call the right rpc" + "Mark done and schedule next button should call the right rpc and not trigger an action" + ); +}); + +QUnit.test('[technical] activity mark done & schedule next with new action', async function (assert) { + assert.expect(3); + + const bus = new Bus(); + bus.on('do-action', null, payload => { + assert.step('activity_action'); + assert.deepEqual( + payload.action, + { type: 'ir.actions.act_window' }, + "The content of the action should be correct" + ); + }); + await this.start({ + async mockRPC(route, args) { + if (route === '/web/dataset/call_kw/mail.activity/action_feedback_schedule_next') { + return { type: 'ir.actions.act_window' }; + } + return this._super(...arguments); + }, + env: { bus }, + }); + const activity = this.env.models['mail.activity'].create({ + canWrite: true, + category: 'not_upload_file', + id: 12, + thread: [['insert', { id: 42, model: 'res.partner' }]], + }); + await this.createActivityMarkDonePopoverComponent(activity); + + await afterNextRender(() => { + document.querySelector('.o_ActivityMarkDonePopover_doneScheduleNextButton').click(); + }); + assert.verifySteps( + ['activity_action'], + "The action returned by the route should be executed" ); }); diff --git a/addons/mail/static/src/models/activity/activity.js b/addons/mail/static/src/models/activity/activity.js index 5b9af7013ca..b2d8ef3cb13 100644 --- a/addons/mail/static/src/models/activity/activity.js +++ b/addons/mail/static/src/models/activity/activity.js @@ -204,6 +204,10 @@ function factory(dependencies) { this.thread.refresh(); const thread = this.thread; this.delete(); + if (!action) { + thread.refreshActivities(); + return; + } this.env.bus.trigger('do-action', { action, options: { |
