Skip to content

Commit

Permalink
Fix bug webclient#412
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Apr 26, 2023
1 parent 5883fe9 commit 9be018e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,11 @@ class Form {

let domain: string | undefined = undefined;

if (
tagAttributes["domain"] &&
tagAttributes["domain"] !== "" &&
tagAttributes["domain"] !== "[]"
) {
if (checkIfDomainHasValue(tagAttributes["domain"])) {
domain = tagAttributes["domain"];
}

if (
this._fields[tagAttributes.name] &&
this._fields[tagAttributes.name].domain &&
this._fields[tagAttributes.name].domain !== "" &&
this._fields[tagAttributes.name].domain !== "[]"
) {
if (checkIfDomainHasValue(this._fields[tagAttributes.name]?.domain)) {
domain = this._fields[tagAttributes.name].domain;
}

Expand Down Expand Up @@ -265,4 +256,15 @@ class Form {
}
}

function checkIfDomainHasValue(domain: any) {
if (!domain) {
return false;
}
if (Array.isArray(domain) && domain.length > 0) {
return true;
} else if (typeof domain === "string" && domain !== "" && domain !== "[]") {
return true;
}
return false;
}
export default Form;
21 changes: 21 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3171,4 +3171,25 @@ describe("A Form", () => {
const field = form.findById("bank") as Field;
expect(field.domain).toBeDefined();
});

it("Should be able to parse domain in XML with domain as [] in fields", () => {
const arch = `<form>
<field name="llista_preu" domain="[('tarifes_atr_compatibles', '=', tarifa), ('type', '=', 'sale')]"/>
</form>`;
const fields = {
llista_preu: {
type: "many2one",
domain: [],
},
};
const form = new Form(fields);
form.parse(arch, {
values: {},
});
const field = form.findById("llista_preu") as Field;
expect(field.domain).toBeDefined();
expect(field.domain).toBe(
"[('tarifes_atr_compatibles', '=', tarifa), ('type', '=', 'sale')]"
);
});
});

0 comments on commit 9be018e

Please sign in to comment.