summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-08-28 12:28:06 +0200
committerAaron Bohy <aab@odoo.com>2017-08-29 10:38:36 +0200
commitf24c83efcc47b24ac8fc7a8add8d2ce39a89ebdf (patch)
tree3ca8de677f73b314f39745fcfb2c374517e26ef7 /addons
parente1cbaf7af7b1a52c6cb10a8f162bb10aa7016c95 (diff)
[FIX] web,mail: keep changes when scheduling an activity
The problem occurred in form view, in edit mode, when the user did some changes in the form, and then clicked on 'Log or schedule an activity'. When validating the activity, the fields mail_activity and mail_thread were reloaded but all changes were discarded in the process. This rev. ensures to reload the requested field without discarding the changes.
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/static/src/js/chatter.js5
-rw-r--r--addons/mail/static/tests/chatter_tests.js59
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js5
3 files changed, 65 insertions, 4 deletions
diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js
index c799cf6a70a..f5a85948762 100644
--- a/addons/mail/static/src/js/chatter.js
+++ b/addons/mail/static/src/js/chatter.js
@@ -288,7 +288,10 @@ var Chatter = Widget.extend(chat_mixin, {
if (this.fields.thread && event.data.thread) {
fieldNames.push(this.fields.thread.name);
}
- this.trigger_up('reload', {fieldNames: fieldNames});
+ this.trigger_up('reload', {
+ fieldNames: fieldNames,
+ keepChanges: true,
+ });
},
_onScheduleActivity: function () {
this.fields.activity.scheduleActivity(false);
diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js
index f268851463d..760a6bcf6cd 100644
--- a/addons/mail/static/tests/chatter_tests.js
+++ b/addons/mail/static/tests/chatter_tests.js
@@ -13,7 +13,6 @@ var BasicComposer = Composers.BasicComposer;
var createAsyncView = testUtils.createAsyncView;
var createView = testUtils.createView;
-var createAsyncView = testUtils.createAsyncView;
QUnit.module('mail', {}, function () {
@@ -496,7 +495,7 @@ QUnit.test('chatter: post, receive and star messages', function (assert) {
});
QUnit.test('form activity widget: schedule next activity', function (assert) {
- assert.expect(4);
+ assert.expect(5);
this.data.partner.records[0].activity_ids = [1];
this.data.partner.records[0].activity_state = 'today';
this.data['mail.activity'].records = [{
@@ -508,6 +507,7 @@ QUnit.test('form activity widget: schedule next activity', function (assert) {
activity_type_id: 2,
}];
+ var checkReadArgs = false;
var form = createView({
View: FormView,
model: 'partner',
@@ -529,6 +529,10 @@ QUnit.test('form activity widget: schedule next activity', function (assert) {
"the feedback should be sent correctly");
return $.when();
}
+ if (args.method === 'read' && checkReadArgs) {
+ assert.deepEqual(args.args[1], ['activity_ids', 'message_ids'],
+ "should only read the mail fields");
+ }
return this._super.apply(this, arguments);
},
intercepts: {
@@ -555,6 +559,8 @@ QUnit.test('form activity widget: schedule next activity', function (assert) {
view_type: "form",
views: [[false, "form"]],
}, "should do a do_action with correct parameters");
+ checkReadArgs = true; // should re-read the activities when closing the dialog
+ event.data.options.on_close();
},
},
});
@@ -567,6 +573,55 @@ QUnit.test('form activity widget: schedule next activity', function (assert) {
form.destroy();
});
+QUnit.test('form activity widget: schedule activity does not discard changes', function (assert) {
+ assert.expect(1);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<sheet>' +
+ '<field name="foo"/>' +
+ '</sheet>' +
+ '<div class="oe_chatter">' +
+ '<field name="activity_ids" widget="mail_activity"/>' +
+ '</div>' +
+ '</form>',
+ res_id: 2,
+ mockRPC: function (route, args) {
+ if (args.method === 'write') {
+ assert.deepEqual(args.args[1], {foo: 'new value'},
+ "should correctly save the change");
+ }
+ return this._super.apply(this, arguments);
+ },
+ intercepts: {
+ get_bus: function (event) {
+ event.stopPropagation();
+ event.data.callback(new Bus());
+ },
+ do_action: function (event) {
+ event.data.options.on_close();
+ },
+ },
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ // update value of foo field
+ form.$('.o_field_widget[name=foo]').val('new value').trigger('input');
+
+ // schedule an activity (this triggers a do_action)
+ form.$('.o_chatter_button_schedule_activity').click();
+
+ // save the record
+ form.$buttons.find('.o_form_button_save').click();
+
+ form.destroy();
+});
+
QUnit.test('form activity widget: mark as done and remove', function (assert) {
assert.expect(14);
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index cfdee6793dd..32570038987 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -546,7 +546,10 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
this.model.reload(handle).then(this._confirmSave.bind(this, handle));
} else {
// no db_id given, so reload the main record
- this.reload({fieldNames: data.fieldNames});
+ this.reload({
+ fieldNames: data.fieldNames,
+ keepChanges: data.keepChanges || false,
+ });
}
},
/**