2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 12:10:06 +00:00

fix: Mandatory check

This commit is contained in:
Faris Ansari 2019-12-24 15:40:31 +05:30
parent 30f5ca1a2e
commit 827cad114a

View File

@ -187,15 +187,17 @@ module.exports = class BaseDocument extends Observable {
}
validateMandatory() {
let missingMandatory = [getMissingMandatory(this)];
let checkForMandatory = [this];
let tableFields = this.meta.fields.filter(df => df.fieldtype === 'Table');
tableFields.map(df => {
let rows = this[df.fieldname];
for (let row of rows) {
missingMandatory = missingMandatory.concat(getMissingMandatory(row));
}
checkForMandatory = [...checkForMandatory, ...rows];
});
let missingMandatory = checkForMandatory
.map(doc => getMissingMandatory(doc))
.filter(Boolean);
if (missingMandatory.length > 0) {
let fields = missingMandatory.join('\n');
let message = frappe._('Value missing for {0}', fields);
@ -217,7 +219,7 @@ module.exports = class BaseDocument extends Observable {
})
.join(', ');
if (doc.meta.isChild) {
if (message && doc.meta.isChild) {
let parentfield = doc.parentdoc.meta.getField(doc.parentfield);
message = `${parentfield.label} Row ${doc.idx + 1}: ${message}`;
}