mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
3e466c647c
- get form to render - minor ui fixes
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
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: {
|
|
formula: async () => this.getAutoDebitCredit('debit'),
|
|
dependsOn: ['credit'],
|
|
},
|
|
credit: {
|
|
formula: async () => this.getAutoDebitCredit('credit'),
|
|
dependsOn: ['debit'],
|
|
},
|
|
};
|
|
|
|
static filters: FiltersMap = {
|
|
account: () => ({ isGroup: false }),
|
|
};
|
|
}
|