2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 20:11:15 +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() { validateMandatory() {
let missingMandatory = [getMissingMandatory(this)]; let checkForMandatory = [this];
let tableFields = this.meta.fields.filter(df => df.fieldtype === 'Table'); let tableFields = this.meta.fields.filter(df => df.fieldtype === 'Table');
tableFields.map(df => { tableFields.map(df => {
let rows = this[df.fieldname]; let rows = this[df.fieldname];
for (let row of rows) { checkForMandatory = [...checkForMandatory, ...rows];
missingMandatory = missingMandatory.concat(getMissingMandatory(row));
}
}); });
let missingMandatory = checkForMandatory
.map(doc => getMissingMandatory(doc))
.filter(Boolean);
if (missingMandatory.length > 0) { if (missingMandatory.length > 0) {
let fields = missingMandatory.join('\n'); let fields = missingMandatory.join('\n');
let message = frappe._('Value missing for {0}', fields); let message = frappe._('Value missing for {0}', fields);
@ -217,7 +219,7 @@ module.exports = class BaseDocument extends Observable {
}) })
.join(', '); .join(', ');
if (doc.meta.isChild) { if (message && doc.meta.isChild) {
let parentfield = doc.parentdoc.meta.getField(doc.parentfield); let parentfield = doc.parentdoc.meta.getField(doc.parentfield);
message = `${parentfield.label} Row ${doc.idx + 1}: ${message}`; message = `${parentfield.label} Row ${doc.idx + 1}: ${message}`;
} }