summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAdrien Dieudonne <adr@odoo.com>2017-08-09 13:59:21 +0200
committerAdrien Dieudonne <adr@odoo.com>2017-08-10 10:33:05 +0200
commit3a886327a6d39367d0f75140a0297d66e2e7fb23 (patch)
treebe66be000129e450a9172666b977f94acb4b42dd /addons
parent1e8f6d01ffe324348ce5d75f8643f170f6478657 (diff)
[FIX] pad: don't consider record as dirty
Before this rev., when the user opened a form view containing a pad widget, with a pad url already configured, a dialog directly popped asking "The record has been modified, your changes will be discarded. Are you sure you want to ?". This is because of an unconventional behavior of this widget: the field actually encodes an url, the one of the pad to display. When the user saves, a write is forced so that the server can retrieve the pad's content and store it in DB. To force the write, the widget always notifies a fake change on the url. However, we don't want this change to trigger the confirm dialog. With this rev., this fake change doesn't make the record 'dirty'.
Diffstat (limited to 'addons')
-rw-r--r--addons/pad/static/src/js/pad.js2
-rw-r--r--addons/pad/static/tests/pad_tests.js36
2 files changed, 37 insertions, 1 deletions
diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js
index 4068ff24ead..1d162bdbc87 100644
--- a/addons/pad/static/src/js/pad.js
+++ b/addons/pad/static/src/js/pad.js
@@ -55,7 +55,7 @@ var FieldPad = AbstractField.extend({
// Guess what we decided...
var url = {};
url.toJSON = _.constant(this.url);
- this._setValue(url);
+ this._setValue(url, {doNotSetDirty: true});
}
return this._super.apply(this, arguments);
diff --git a/addons/pad/static/tests/pad_tests.js b/addons/pad/static/tests/pad_tests.js
index 5d18e55c1e0..dedf799db66 100644
--- a/addons/pad/static/tests/pad_tests.js
+++ b/addons/pad/static/tests/pad_tests.js
@@ -193,5 +193,41 @@ QUnit.module('pad widget', {
delete FieldPad.prototype.isPadConfigured;
});
+ QUnit.test('pad widget is not considered dirty at edition', function (assert) {
+ assert.expect(2);
+
+ var form = createView({
+ View: FormView,
+ model: 'task',
+ data: this.data,
+ arch:'<form>' +
+ '<sheet>' +
+ '<group>' +
+ '<field name="description" widget="pad"/>' +
+ '</group>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 2,
+ mockRPC: function (route, args) {
+ if (!args.method) {
+ return $.when(true);
+ }
+ return this._super.apply(this, arguments);
+ },
+ session: {
+ userName: "batman",
+ },
+ });
+ form.$buttons.find('.o_form_button_edit').click();
+ var def = form.canBeDiscarded();
+
+ assert.strictEqual($('.modal').length, 0,
+ "should have no confirmation modal opened");
+
+ assert.strictEqual(def.state(), 'resolved',
+ "can be discarded was succesfully resolved");
+ form.destroy();
+ delete FieldPad.prototype.isPadConfigured;
+ });
});