2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 19:29:02 +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.

89 lines
2.2 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,
2022-04-27 12:02:43 +00:00
ListViewSettings
} from 'fyo/model/types';
import { DateTime } from 'luxon';
import { getLedgerLinkAction } from 'models/helpers';
import { Transactional } from 'models/Transactional/Transactional';
import Money from 'pesa/dist/types/src/money';
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;
}
2022-04-25 06:33:31 +00:00
static defaults: DefaultMap = {
date: () => DateTime.local().toISODate(),
};
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 {
formRoute: (name) => `/edit/JournalEntry/${name}`,
columns: [
'date',
{
2022-04-27 12:02:43 +00:00
label: t`Status`,
fieldtype: 'Select',
size: 'small',
render(doc) {
let status = 'Draft';
let color = 'gray';
if (doc.submitted) {
color = 'green';
status = 'Submitted';
}
if (doc.cancelled) {
color = 'red';
status = 'Cancelled';
}
return {
template: `<Badge class="text-xs" color="${color}">${status}</Badge>`,
};
},
},
{
2022-04-27 12:02:43 +00:00
label: t`Entry ID`,
fieldtype: 'Data',
fieldname: 'name',
getValue(doc) {
return doc.name as string;
},
},
'entryType',
'referenceNumber',
],
};
}
}