2023-12-22 00:19:13 +00:00
|
|
|
import { Fyo } from 'fyo';
|
2023-12-22 08:50:35 +00:00
|
|
|
import { DocValueMap } from 'fyo/core/types';
|
2024-08-09 05:11:54 +00:00
|
|
|
import { Action, FiltersMap, ListViewSettings } from 'fyo/model/types';
|
2023-12-22 00:19:13 +00:00
|
|
|
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';
|
2024-08-09 05:11:54 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
|
|
|
import { Party } from '../Party/Party';
|
2023-12-22 00:19:13 +00:00
|
|
|
|
|
|
|
export class SalesQuote extends Invoice {
|
|
|
|
items?: SalesQuoteItem[];
|
2024-08-09 05:11:54 +00:00
|
|
|
party?: string;
|
|
|
|
name?: string;
|
|
|
|
referenceType?:
|
|
|
|
| ModelNameEnum.SalesInvoice
|
|
|
|
| ModelNameEnum.PurchaseInvoice
|
|
|
|
| ModelNameEnum.Lead;
|
2023-12-22 00:19:13 +00:00
|
|
|
|
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
|
2023-12-22 00:19:13 +00:00
|
|
|
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),
|
2023-12-22 00:19:13 +00:00
|
|
|
date: new Date().toISOString(),
|
|
|
|
terms,
|
|
|
|
numberSeries,
|
|
|
|
quote: this.name,
|
2023-12-22 08:50:35 +00:00
|
|
|
items: [],
|
2024-08-08 09:46:31 +00:00
|
|
|
submitted: false,
|
2023-12-22 00:19:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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));
|
2023-12-22 00:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!invoice.items?.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return invoice;
|
|
|
|
}
|
|
|
|
|
2024-08-09 05:11:54 +00:00
|
|
|
static filters: FiltersMap = {
|
|
|
|
numberSeries: (doc: Doc) => ({ referenceType: doc.schemaName }),
|
|
|
|
};
|
|
|
|
|
|
|
|
async afterSubmit(): Promise<void> {
|
|
|
|
await super.afterSubmit();
|
|
|
|
|
|
|
|
if (this.referenceType == ModelNameEnum.Lead) {
|
|
|
|
const partyDoc = (await this.loadAndGetLink('party')) as Party;
|
|
|
|
|
|
|
|
await partyDoc.setAndSync('status', 'Quotation');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-22 00:19:13 +00:00
|
|
|
static getListViewSettings(): ListViewSettings {
|
|
|
|
return {
|
|
|
|
columns: [
|
|
|
|
'name',
|
|
|
|
getTransactionStatusColumn(),
|
|
|
|
'party',
|
|
|
|
'date',
|
|
|
|
'baseGrandTotal',
|
|
|
|
'outstandingAmount',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static getActions(fyo: Fyo): Action[] {
|
|
|
|
return getQuoteActions(fyo, ModelNameEnum.SalesQuote);
|
|
|
|
}
|
|
|
|
}
|