Skip to content

Commit

Permalink
Merge pull request #166 from gisce/fix-evaluate-many2one-on-attrs
Browse files Browse the repository at this point in the history
evaluateFieldComparison use index 0 of many2one
  • Loading branch information
ecarreras authored Jan 22, 2025
2 parents 8ff865b + f65429e commit 4502c84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/helpers/attributeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ const evaluateFieldComparison = ({
) {
result.modifiedExpectedValue = undefined;
} else {
result.modifiedValueInObject =
result.modifiedValueInObject === undefined
? false
: result.modifiedValueInObject;
result.modifiedValueInObject =
result.modifiedValueInObject === null
? false
: result.modifiedValueInObject;
if (result.modifiedValueInObject === undefined) {
result.modifiedValueInObject = false;
} else if (
Array.isArray(result.modifiedValueInObject) &&
result.modifiedValueInObject[0] !== undefined
) {
result.modifiedValueInObject = result.modifiedValueInObject[0];
}

if (result.modifiedValueInObject === null) {
result.modifiedValueInObject = false;
}
}

if (
Expand Down
14 changes: 14 additions & 0 deletions src/spec/attributeParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,20 @@ describe("An Attribute Parser", () => {
});
expect(evaluatedAttrs.invisible).toBeTruthy();
});
it("should properly use the id of a many2one value", () => {
const tagAttributes = {
json_attrs:
'{"invisible":{"condition":"AND","rules":[{"field":"autoconsum_id","operator":"=","value":10}]}}',
};
const values = { autoconsum_id: [10, "Autoconsum"] };
const evaluatedAttrs = evaluateAttributes({
tagAttributes,
values,
fields,
fallbackMode: false,
});
expect(evaluatedAttrs.invisible).toBeTruthy();
});
it("should properly parse a many2one attribute with undefined value", () => {
const tagAttributes = {
json_attrs:
Expand Down

0 comments on commit 4502c84

Please sign in to comment.