2
0
mirror of https://github.com/frappe/books.git synced 2024-11-15 09:54:04 +00:00
books/models/baseModels/SalesQuote/SalesQuote.ts

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

68 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Fyo } from 'fyo';
2023-12-22 08:50:35 +00:00
import { DocValueMap } from 'fyo/core/types';
import { Action, ListViewSettings } from 'fyo/model/types';
import { ModelNameEnum } from 'models/types';
import { getQuoteActions, getTransactionStatusColumn } from '../../helpers';
import { Invoice } from '../Invoice/Invoice';
import { SalesQuoteItem } from '../SalesQuoteItem/SalesQuoteItem';
2023-12-22 08:50:35 +00:00
import { Defaults } from '../Defaults/Defaults';
export class SalesQuote extends Invoice {
items?: SalesQuoteItem[];
2023-12-22 08:50:35 +00:00
// This is an inherited method and it must keep the async from the parent
// class
// eslint-disable-next-line @typescript-eslint/require-await
async getPosting() {
return null;
}
async getInvoice(): Promise<Invoice | null> {
if (!this.isSubmitted) {
return null;
}
const schemaName = ModelNameEnum.SalesInvoice;
const defaults = (this.fyo.singles.Defaults as Defaults) ?? {};
const terms = defaults.salesInvoiceTerms ?? '';
const numberSeries = defaults.salesInvoiceNumberSeries ?? undefined;
2023-12-22 08:50:35 +00:00
const data: DocValueMap = {
...this.getValidDict(false, true),
date: new Date().toISOString(),
terms,
numberSeries,
quote: this.name,
2023-12-22 08:50:35 +00:00
items: [],
};
const invoice = this.fyo.doc.getNewDoc(schemaName, data) as Invoice;
for (const row of this.items ?? []) {
2023-12-22 08:50:35 +00:00
await invoice.append('items', row.getValidDict(false, true));
}
if (!invoice.items?.length) {
return null;
}
return invoice;
}
static getListViewSettings(): ListViewSettings {
return {
columns: [
'name',
getTransactionStatusColumn(),
'party',
'date',
'baseGrandTotal',
'outstandingAmount',
],
};
}
static getActions(fyo: Fyo): Action[] {
return getQuoteActions(fyo, ModelNameEnum.SalesQuote);
}
}