[FIX] web: add support for TRUE_LEAF and FALSE_LEAF in ModelFieldSelector

before this commit, domain selector widget does not support
TRUE_LEAF and FALSE_LEAF i.e. [(1, '=', 1)] and [(0, '=', 1)] respectively,
the reason is the chain part of the domain i.e. field name has value 1/0 and
we don't have field name like 1 and 0 in domain and hence ModelFieldSelector
don't accept it

after this commit, domain selector can handle this special two domains which is
[(1, '=', 1)] and [(0, '=', 1)], add support for chain with 1/0 in ModelFieldSelector

task- 1998145

closes odoo/odoo#35603

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>


Co-authored-by: Mohammed Shekha <msh@odoo.com>
This commit is contained in:
Jinal Patel
2019-08-09 12:32:27 +00:00
co-authored by Mohammed Shekha
parent a72b23f6b5
commit f0fdfbf44e
4 changed files with 57 additions and 4 deletions
@@ -652,7 +652,7 @@ var DomainLeaf = DomainNode.extend({
this.fieldSelector = new ModelFieldSelector(
this,
this.model,
this.chain ? this.chain.split(".") : [],
this.chain !== undefined ? this.chain.toString().split(".") : [],
this.options
);
defs.push(this.fieldSelector.appendTo($("<div/>")).then((function () {
@@ -301,11 +301,16 @@ var ModelFieldSelector = Widget.extend({
}).bind(this));
function processChain(chain) {
var field = this._getLastPageField(chain.pop());
var fieldName = chain.pop();
var field = this._getLastPageField(fieldName);
if (field && field.relation && chain.length > 0) { // Fetch next chain node if any and possible
return this._pushPageData(field.relation).then(processChain.bind(this, chain));
} else if (field && chain.length === 0) { // Last node fetched
return Promise.resolve();
} else if (!field && fieldName === "1") { // TRUE_LEAF
this._validate(true);
} else if (!field && fieldName === "0") { // FALSE_LEAF
this._validate(true);
} else { // Wrong node chain
this._validate(false);
}
+10 -2
View File
@@ -767,8 +767,16 @@
<i class="fa fa-chevron-right" role="img" aria-label="Followed by" title="Followed by"/>
</t>
<span class="o_field_selector_chain_part">
<t t-set="fieldInfo" t-value="_.findWhere(pages[fieldName_index], {'name': fieldName})"/>
<t t-esc="fieldInfo &amp;&amp; fieldInfo.string || '?'"/>
<t t-if="fieldName === '1'">
<t t-esc="fieldName"/>
</t>
<t t-elif="fieldName === '0'">
<t t-esc="fieldName"/>
</t>
<t t-else="">
<t t-set="fieldInfo" t-value="_.findWhere(pages[fieldName_index], {'name': fieldName})"/>
<t t-esc="fieldInfo &amp;&amp; fieldInfo.string || '?'"/>
</t>
</span>
</t>
</t>
@@ -248,6 +248,46 @@ QUnit.module('ModelFieldSelector', {
fieldSelector.destroy();
});
QUnit.test("create a field chain with value 1 i.e. TRUE_LEAF", async function (assert) {
assert.expect(1);
var $target = $("#qunit-fixture");
//create the field selector with domain value ["1"]
var fieldSelector = new ModelFieldSelector(null, "partner", ["1"], {
readonly: false,
showSearchInput: false,
});
testUtils.mock.addMockEnvironment(fieldSelector, {data: this.data});
await fieldSelector.appendTo($target);
var $fieldName = fieldSelector.$('.o_field_selector_chain_part');
assert.strictEqual($fieldName.text().trim(), "1",
"field name value should be 1.");
fieldSelector.destroy();
});
QUnit.test("create a field chain with value 0 i.e. FALSE_LEAF", async function (assert) {
assert.expect(1);
var $target = $("#qunit-fixture");
//create the field selector with domain value ["0"]
var fieldSelector = new ModelFieldSelector(null, "partner", ["0"], {
readonly: false,
showSearchInput: false,
});
testUtils.mock.addMockEnvironment(fieldSelector, {data: this.data});
await fieldSelector.appendTo($target);
var $fieldName = fieldSelector.$('.o_field_selector_chain_part');
assert.strictEqual($fieldName.text().trim(), "0",
"field name value should be 0.");
fieldSelector.destroy();
});
});
});
});