[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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user