[IMP] web: better process modifiers in mock server

Before this commit, modifiers were partially processed by the mock
server. Now, it should be a better approximation of what the server
does:
- Take the invisible/readonly/required from "attrs"
- Merge invisible with the "states" ([["state", "not in", states]])
- Override if invisible/readonly/required attribute is present

+ Adapt some tests
This commit is contained in:
qsm-odoo
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 654f932b3c
commit e3546bb1b8
2 changed files with 26 additions and 12 deletions
+14 -8
View File
@@ -174,17 +174,23 @@ var MockServer = Class.extend({
var modifiers = {};
if (node.attrs.attrs) {
var attrs = pyeval.py_eval(node.attrs.attrs);
if (attrs.invisible) {
modifiers.invisible = attrs.invisible;
}
if (attrs.readonly) {
modifiers.readonly = attrs.readonly;
}
_.extend(modifiers, attrs);
delete node.attrs.attrs;
}
if (node.attrs.invisible) {
modifiers.invisible = pyeval.py_eval(node.attrs.invisible);
if (node.attrs.states) {
if (!modifiers.invisible) {
modifiers.invisible = [];
}
modifiers.invisible.push(["state", "not in", node.attrs.states.split(",")]);
}
_.each(["invisible", "readonly", "required"], function (a) {
if (node.attrs[a]) {
var v = pyeval.py_eval(node.attrs[a]);
if (v || modifiers[a] === undefined) {
modifiers[a] = v;
}
}
});
node.attrs.modifiers = JSON.stringify(modifiers);
if (node.tag === 'field') {
fieldNodes[node.attrs.name] = node;
+12 -4
View File
@@ -30,6 +30,7 @@ QUnit.module('Views', {
selection: [[1, "Low"], [2, "Medium"], [3, "High"]],
default: 1,
},
state: {string: "State", type: "selection", selection: [["ab", "AB"], ["cd", "CD"], ["ef", "EF"]]}
},
records: [{
id: 1,
@@ -41,6 +42,7 @@ QUnit.module('Views', {
p: [],
timmy: [],
trululu: 4,
state: "ab",
}, {
id: 2,
display_name: "second record",
@@ -51,9 +53,11 @@ QUnit.module('Views', {
p: [],
timmy: [],
trululu: 1,
state: "cd",
}, {
id: 4,
display_name: "aaa"
display_name: "aaa",
state: "ef",
}],
onchanges: {},
},
@@ -529,7 +533,7 @@ QUnit.module('Views', {
});
QUnit.test('buttons in form view', function (assert) {
assert.expect(6);
assert.expect(7);
var rpcCount = 0;
@@ -538,8 +542,9 @@ QUnit.module('Views', {
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="state" invisible="1"/>' +
'<header>' +
'<button name="post" class="p" states="draft" string="Confirm" type="object"/>' +
'<button name="post" class="p" states="ab,ef" string="Confirm" type="object"/>' +
'<button name="some_method" class="s" string="Do it" type="object"/>' +
'</header>' +
'<sheet>' +
@@ -560,6 +565,9 @@ QUnit.module('Views', {
assert.strictEqual(form.$('.o_form_statusbar button').length, 2,
"should have 2 buttons in the statusbar");
assert.strictEqual(form.$('.o_form_statusbar button:visible').length, 1,
"should have only 1 visible button in the statusbar");
testUtils.intercept(form, 'execute_action', function (event) {
assert.strictEqual(event.data.action_data.name, "post",
"should trigger execute_action with correct method name");
@@ -592,7 +600,7 @@ QUnit.module('Views', {
data: this.data,
arch: '<form string="Partners">' +
'<header>' +
'<button name="post" class="p" states="draft" string="Confirm" type="object"/>' +
'<button name="post" class="p" string="Confirm" type="object"/>' +
'<button name="some_method" class="s" string="Do it" type="object"/>' +
'</header>' +
'<sheet>' +