2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts
18alantom de7e5ba807 refactor: rename 'frappe' to 'fyo' outside src
- cause now most of it is different from what it was
2022-05-23 16:18:22 +05:30

35 lines
948 B
TypeScript

import Doc from 'fyo/model/doc';
import { FiltersMap, FormulaMap } from 'fyo/model/types';
import Money from 'pesa/dist/types/src/money';
export class JournalEntryAccount extends Doc {
getAutoDebitCredit(type: 'debit' | 'credit') {
const otherType = type === 'debit' ? 'credit' : 'debit';
const otherTypeValue = this.get(otherType) as Money;
if (!otherTypeValue.isZero()) {
return this.fyo.pesa(0);
}
const totalType = this.parentdoc!.getSum('accounts', type, false) as Money;
const totalOtherType = this.parentdoc!.getSum(
'accounts',
otherType,
false
) as Money;
if (totalType.lt(totalOtherType)) {
return totalOtherType.sub(totalType);
}
}
formulas: FormulaMap = {
debit: async () => this.getAutoDebitCredit('debit'),
credit: async () => this.getAutoDebitCredit('credit'),
};
static filters: FiltersMap = {
account: () => ({ isGroup: false }),
};
}