2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00
books/models/baseModels/JournalEntry/JournalEntry.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-04-27 12:02:43 +00:00
import { Fyo, t } from 'fyo';
import { Doc } from 'fyo/model/doc';
import {
Action,
DefaultMap,
FiltersMap,
HiddenMap,
ListViewSettings,
} from 'fyo/model/types';
2022-06-14 09:10:46 +00:00
import {
getDocStatus,
getLedgerLinkAction,
getNumberSeries,
getStatusText,
statusColor,
2022-06-14 09:10:46 +00:00
} from 'models/helpers';
import { Transactional } from 'models/Transactional/Transactional';
2022-05-23 05:30:54 +00:00
import { Money } from 'pesa';
import { LedgerPosting } from '../../Transactional/LedgerPosting';
export class JournalEntry extends Transactional {
accounts?: Doc[];
async getPosting() {
const posting: LedgerPosting = new LedgerPosting(this, this.fyo);
for (const row of this.accounts ?? []) {
const debit = row.debit as Money;
const credit = row.credit as Money;
const account = row.account as string;
if (!debit.isZero()) {
await posting.debit(account, debit);
} else if (!credit.isZero()) {
await posting.credit(account, credit);
}
}
return posting;
}
hidden: HiddenMap = {
referenceNumber: () =>
!(this.referenceNumber || !(this.isSubmitted || this.isCancelled)),
referenceDate: () =>
!(this.referenceDate || !(this.isSubmitted || this.isCancelled)),
userRemark: () =>
!(this.userRemark || !(this.isSubmitted || this.isCancelled)),
attachment: () =>
!(this.attachment || !(this.isSubmitted || this.isCancelled)),
};
2022-04-25 06:33:31 +00:00
static defaults: DefaultMap = {
2022-10-12 09:29:43 +00:00
numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo),
date: () => new Date(),
};
static filters: FiltersMap = {
numberSeries: () => ({ referenceType: 'JournalEntry' }),
};
static getActions(fyo: Fyo): Action[] {
return [getLedgerLinkAction(fyo)];
}
2022-04-27 12:02:43 +00:00
static getListViewSettings(): ListViewSettings {
return {
columns: [
2022-05-12 05:52:25 +00:00
'name',
{
2022-04-27 12:02:43 +00:00
label: t`Status`,
fieldname: 'status',
fieldtype: 'Select',
render(doc) {
2022-06-14 09:10:46 +00:00
const status = getDocStatus(doc);
const color = statusColor[status] ?? 'gray';
const label = getStatusText(status);
return {
2022-06-14 09:10:46 +00:00
template: `<Badge class="text-xs" color="${color}">${label}</Badge>`,
};
},
},
2022-05-12 05:52:25 +00:00
'date',
'entryType',
'referenceNumber',
],
};
}
}