mirror of
https://github.com/frappe/books.git
synced 2024-12-23 19:39:07 +00:00
d0571a2450
- update files to ignore - delete babel.config.js
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { Doc } from 'fyo/model/doc';
|
|
import { FiltersMap, FormulaMap } from 'fyo/model/types';
|
|
import { Money } from 'pesa';
|
|
|
|
export class JournalEntryAccount extends Doc {
|
|
getAutoDebitCredit(type: 'debit' | 'credit') {
|
|
const currentValue = this.get(type) as Money;
|
|
if (!currentValue.isZero()) {
|
|
return;
|
|
}
|
|
|
|
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: () => this.getAutoDebitCredit('debit'),
|
|
},
|
|
credit: {
|
|
formula: () => this.getAutoDebitCredit('credit'),
|
|
},
|
|
};
|
|
|
|
static filters: FiltersMap = {
|
|
account: () => ({ isGroup: false }),
|
|
};
|
|
}
|