2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/models/baseModels/PurchaseInvoice/PurchaseInvoice.ts
18alantom 539157d122 feat: add link navigation
- getCreateRoute -> getFormRoute
- update formRoute listconfig
2023-03-03 17:53:03 +05:30

56 lines
1.7 KiB
TypeScript

import { Fyo } from 'fyo';
import { Action, ListViewSettings } from 'fyo/model/types';
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
import { ModelNameEnum } from 'models/types';
import { getInvoiceActions, getTransactionStatusColumn } from '../../helpers';
import { Invoice } from '../Invoice/Invoice';
import { PurchaseInvoiceItem } from '../PurchaseInvoiceItem/PurchaseInvoiceItem';
export class PurchaseInvoice extends Invoice {
items?: PurchaseInvoiceItem[];
async getPosting() {
const exchangeRate = this.exchangeRate ?? 1;
const posting: LedgerPosting = new LedgerPosting(this, this.fyo);
await posting.credit(this.account!, this.baseGrandTotal!);
for (const item of this.items!) {
await posting.debit(item.account!, item.amount!.mul(exchangeRate));
}
if (this.taxes) {
for (const tax of this.taxes) {
await posting.debit(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.credit(discountAccount, discountAmount.mul(exchangeRate));
}
await posting.makeRoundOffEntry();
return posting;
}
static getListViewSettings(): ListViewSettings {
return {
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
columns: [
'name',
getTransactionStatusColumn(),
'party',
'date',
'baseGrandTotal',
'outstandingAmount',
],
};
}
static getActions(fyo: Fyo): Action[] {
return getInvoiceActions(fyo, ModelNameEnum.PurchaseInvoice);
}
}