2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

fix: update JE, fix validation message

This commit is contained in:
18alantom 2021-12-29 13:00:15 +05:30
parent 8583db75d6
commit b4957c3a64
3 changed files with 21 additions and 17 deletions

View File

@ -123,7 +123,10 @@ export default class LedgerPosting {
let { debit, credit } = this.getTotalDebitAndCredit();
if (!debit.eq(credit)) {
throw new Error(
`Total Debit (${debit.round()}) must be equal to Total Credit (${credit.round()})`
`Total Debit: ${frappe.format(
debit,
'Currency'
)} must be equal to Total Credit: ${frappe.format(credit, 'Currency')}`
);
}
}

View File

@ -6,9 +6,9 @@ export default class JournalEntryServer extends BaseDocument {
let entries = new LedgerPosting({ reference: this });
for (let row of this.accounts) {
if (row.debit) {
if (!row.debit.isZero()) {
entries.debit(row.account, row.debit);
} else if (row.credit) {
} else if (!row.credit.isZero()) {
entries.credit(row.account, row.credit);
}
}
@ -31,4 +31,4 @@ export default class JournalEntryServer extends BaseDocument {
async afterRevert() {
await this.getPosting().postReverse();
}
};
}

View File

@ -10,34 +10,35 @@ export default {
target: 'Account',
required: 1,
groupBy: 'rootType',
getFilters: () => ({ isGroup: 0 })
getFilters: () => ({ isGroup: 0 }),
},
{
fieldname: 'debit',
label: 'Debit',
fieldtype: 'Currency',
formula: autoDebitCredit('debit')
formula: autoDebitCredit('debit'),
},
{
fieldname: 'credit',
label: 'Credit',
fieldtype: 'Currency',
formula: autoDebitCredit('credit')
}
formula: autoDebitCredit('credit'),
},
],
tableFields: ['account', 'debit', 'credit']
tableFields: ['account', 'debit', 'credit'],
};
function autoDebitCredit(type = 'debit') {
function autoDebitCredit(type) {
let otherType = type === 'debit' ? 'credit' : 'debit';
return (row, doc) => {
if (row[type] == 0) return null;
if (row[otherType]) return null;
let totalType = doc.getSum('accounts', type);
let totalOtherType = doc.getSum('accounts', otherType);
if (totalType < totalOtherType) {
return totalOtherType - totalType;
return (row, doc) => {
if (!row[otherType].isZero()) return frappe.pesa(0);
let totalType = doc.getSum('accounts', type, false);
let totalOtherType = doc.getSum('accounts', otherType, false);
if (totalType.lt(totalOtherType)) {
return totalOtherType.sub(totalType);
}
};
}