2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00
books/models/baseModels/SalesInvoice/SalesInvoice.ts
2022-11-22 14:42:49 +05:30

50 lines
1.5 KiB
TypeScript

import { ListViewSettings } from 'fyo/model/types';
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
import { getTransactionStatusColumn } from '../../helpers';
import { Invoice } from '../Invoice/Invoice';
import { SalesInvoiceItem } from '../SalesInvoiceItem/SalesInvoiceItem';
export class SalesInvoice extends Invoice {
items?: SalesInvoiceItem[];
async getPosting() {
const exchangeRate = this.exchangeRate ?? 1;
const posting: LedgerPosting = new LedgerPosting(this, this.fyo);
await posting.debit(this.account!, this.baseGrandTotal!);
for (const item of this.items!) {
await posting.credit(item.account!, item.amount!.mul(exchangeRate));
}
if (this.taxes) {
for (const tax of this.taxes!) {
await posting.credit(tax.account!, tax.amount!.mul(exchangeRate));
}
}
const discountAmount = await this.getTotalDiscount();
const discountAccount = this.fyo.singles.AccountingSettings
?.discountAccount as string | undefined;
if (discountAccount && discountAmount.isPositive()) {
await posting.debit(discountAccount, discountAmount.mul(exchangeRate));
}
await posting.makeRoundOffEntry();
return posting;
}
static getListViewSettings(): ListViewSettings {
return {
formRoute: (name) => `/edit/SalesInvoice/${name}`,
columns: [
'name',
getTransactionStatusColumn(),
'party',
'date',
'baseGrandTotal',
'outstandingAmount',
],
};
}
}