2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 20:00:29 +00:00

feat: add convenience function to get fields meta map

This commit is contained in:
18alantom 2021-11-25 14:48:02 +05:30
parent 317eb3116b
commit 0af2ce86f4

View File

@ -194,7 +194,6 @@ module.exports = class BaseDocument extends Observable {
}
validateMandatory() {
const fieldValueMap = this.getFieldValueMap();
let checkForMandatory = [this];
let tableFields = this.meta.fields.filter((df) => df.fieldtype === 'Table');
tableFields.map((df) => {
@ -215,7 +214,7 @@ module.exports = class BaseDocument extends Observable {
function getMissingMandatory(doc) {
let mandatoryFields = doc.meta.fields.filter((df) => {
if (df.required instanceof Function) {
return df.required(fieldValueMap);
return df.required(doc);
}
return df.required;
});
@ -702,4 +701,11 @@ module.exports = class BaseDocument extends Observable {
}, {});
return Object.freeze(fieldValueMap);
}
getFieldMetaMap() {
return this.meta.fields.reduce((obj, meta) => {
obj[meta.fieldname] = meta;
return obj;
}, {});
}
};