[FIX] web: display error dialog when onchanges fails

When the onchange returns a dictionary with a 'warning' key, it is
supposed to fail and display a dialog with the content of the warning.
This commit is contained in:
Géry Debongnie
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 05ec284e9c
commit 044e7bb599
3 changed files with 53 additions and 3 deletions
@@ -951,7 +951,8 @@ var Model = AbstractModel.extend({
*
* @param {Object} record
* @param {string[]} fields changed fields
* @returns
* @returns {Deferred} The returned deferred can fail, in which case the
* fail value will be the warning message received from the server
*/
_applyOnChange: function (record, fields) {
var self = this;
@@ -980,6 +981,9 @@ var Model = AbstractModel.extend({
return this.mutex.exec(function () {
var args = [idList, currentData, fields, onchange_spec, context];
return self.performModelRPC(record.model, 'onchange', args, {}).then(function (result) {
if (result.warning) {
return $.Deferred().reject(result.warning);
}
var defs = [];
_.each(result.value, function (val, name) {
var field = record.fields[name];
@@ -9,6 +9,10 @@ odoo.define('web.FieldManagerMixin', function (require) {
*/
var BasicModel = require('web.BasicModel');
var Dialog = require('web.Dialog');
var core = require('web.core');
var qweb = core.qweb;
return {
custom_events: {
@@ -84,6 +88,12 @@ return {
} else {
self._confirmChange(dataPointID, result, event);
}
}).fail(function (warning) {
new Dialog(self, {
size: 'medium',
title: warning.title,
$content: qweb.render("CrashManager.warning", warning)
}).open();
});
},
/**
+38 -2
View File
@@ -1554,6 +1554,42 @@ QUnit.module('Views', {
assert.strictEqual(form.$('.o_priority .fa-star').length, 2,
'priority widget should have correct value');
});
});
});
QUnit.test('display a dialog if onchange result is a warning', function (assert) {
assert.expect(2);
this.data.partner.onchanges = { foo: true };
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<group><field name="foo"/><field name="int_field"/></group>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
return $.when({
valu: {},
warning: {
title: "Warning",
message: "You must first select a partner"
}
});
}
return this._super.apply(this, arguments);
},
});
form.$buttons.find('.o_form_button_edit').click();
form.$('input').first().val("tralala").trigger('input');
assert.strictEqual($('.modal .modal-title:contains(Warning)').length, 1,
"should have rendered a modal dialog with correct title");
assert.strictEqual($('.modal .modal-body:contains(You must first select a partner)').length, 1,
"should have rendered a modal dialog with correct content");
});
});});