2
0
mirror of https://github.com/frappe/books.git synced 2025-01-03 07:12:21 +00:00

chore: validate and lint typescript

This commit is contained in:
Mildred Ki'Lya 2023-12-22 09:50:35 +01:00
parent 47d90d8756
commit 4dfeb98e4a
8 changed files with 49 additions and 58 deletions

View File

@ -71,7 +71,9 @@ export abstract class Invoice extends Transactional {
returnAgainst?: string; returnAgainst?: string;
get isSales() { get isSales() {
return this.schemaName === 'SalesInvoice' || this.schemaName == 'SalesQuote'; return (
this.schemaName === 'SalesInvoice' || this.schemaName == 'SalesQuote'
);
} }
get isQuote() { get isQuote() {

View File

@ -47,7 +47,10 @@ export abstract class InvoiceItem extends Doc {
itemTaxedTotal?: Money; itemTaxedTotal?: Money;
get isSales() { get isSales() {
return this.schemaName === 'SalesInvoiceItem' || this.schemaName === 'SalesQuoteItem'; return (
this.schemaName === 'SalesInvoiceItem' ||
this.schemaName === 'SalesQuoteItem'
);
} }
get date() { get date() {

View File

@ -1,14 +1,18 @@
import { Fyo } from 'fyo'; import { Fyo } from 'fyo';
import { DocValueMap } from 'fyo/core/types';
import { Action, ListViewSettings } from 'fyo/model/types'; import { Action, ListViewSettings } from 'fyo/model/types';
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
import { ModelNameEnum } from 'models/types'; import { ModelNameEnum } from 'models/types';
import { getQuoteActions, getTransactionStatusColumn } from '../../helpers'; import { getQuoteActions, getTransactionStatusColumn } from '../../helpers';
import { Invoice } from '../Invoice/Invoice'; import { Invoice } from '../Invoice/Invoice';
import { SalesQuoteItem } from '../SalesQuoteItem/SalesQuoteItem'; import { SalesQuoteItem } from '../SalesQuoteItem/SalesQuoteItem';
import { Defaults } from '../Defaults/Defaults';
export class SalesQuote extends Invoice { export class SalesQuote extends Invoice {
items?: SalesQuoteItem[]; items?: SalesQuoteItem[];
// 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() { async getPosting() {
return null; return null;
} }
@ -23,20 +27,18 @@ export class SalesQuote extends Invoice {
const terms = defaults.salesInvoiceTerms ?? ''; const terms = defaults.salesInvoiceTerms ?? '';
const numberSeries = defaults.salesInvoiceNumberSeries ?? undefined; const numberSeries = defaults.salesInvoiceNumberSeries ?? undefined;
const data = { const data: DocValueMap = {
...this, ...this.getValidDict(false, true),
date: new Date().toISOString(), date: new Date().toISOString(),
terms, terms,
numberSeries, numberSeries,
quote: this.name, quote: this.name,
items: [] items: [],
}; };
const invoice = this.fyo.doc.getNewDoc(schemaName, data) as Invoice; const invoice = this.fyo.doc.getNewDoc(schemaName, data) as Invoice;
for (const row of this.items ?? []) { for (const row of this.items ?? []) {
await invoice.append('items', { await invoice.append('items', row.getValidDict(false, true));
...row
});
} }
if (!invoice.items?.length) { if (!invoice.items?.length) {

View File

@ -11,6 +11,7 @@ import {
} from './baseModels/Account/types'; } from './baseModels/Account/types';
import { numberSeriesDefaultsMap } from './baseModels/Defaults/Defaults'; import { numberSeriesDefaultsMap } from './baseModels/Defaults/Defaults';
import { Invoice } from './baseModels/Invoice/Invoice'; import { Invoice } from './baseModels/Invoice/Invoice';
import { SalesQuote } from './baseModels/SalesQuote/SalesQuote';
import { StockMovement } from './inventory/StockMovement'; import { StockMovement } from './inventory/StockMovement';
import { StockTransfer } from './inventory/StockTransfer'; import { StockTransfer } from './inventory/StockTransfer';
import { InvoiceStatus, ModelNameEnum } from './types'; import { InvoiceStatus, ModelNameEnum } from './types';
@ -19,9 +20,7 @@ export function getQuoteActions(
fyo: Fyo, fyo: Fyo,
schemaName: ModelNameEnum.SalesQuote schemaName: ModelNameEnum.SalesQuote
): Action[] { ): Action[] {
return [ return [getMakeInvoiceAction(fyo, schemaName)];
getMakeInvoiceAction(fyo, schemaName),
];
} }
export function getInvoiceActions( export function getInvoiceActions(
@ -76,7 +75,10 @@ export function getMakeStockTransferAction(
export function getMakeInvoiceAction( export function getMakeInvoiceAction(
fyo: Fyo, fyo: Fyo,
schemaName: ModelNameEnum.Shipment | ModelNameEnum.PurchaseReceipt | ModelNameEnum.SalesQuote schemaName:
| ModelNameEnum.Shipment
| ModelNameEnum.PurchaseReceipt
| ModelNameEnum.SalesQuote
): Action { ): Action {
let label = fyo.t`Sales Invoice`; let label = fyo.t`Sales Invoice`;
if (schemaName === ModelNameEnum.PurchaseReceipt) { if (schemaName === ModelNameEnum.PurchaseReceipt) {
@ -88,13 +90,13 @@ export function getMakeInvoiceAction(
group: fyo.t`Create`, group: fyo.t`Create`,
condition: (doc: Doc) => { condition: (doc: Doc) => {
if (schemaName === ModelNameEnum.SalesQuote) { if (schemaName === ModelNameEnum.SalesQuote) {
return doc.isSubmitted return doc.isSubmitted;
} else { } else {
return doc.isSubmitted && !doc.backReference return doc.isSubmitted && !doc.backReference;
} }
}, },
action: async (doc: Doc) => { action: async (doc: Doc) => {
let invoice = await (doc as SalesQuote | StockTransfer).getInvoice(); const invoice = await (doc as SalesQuote | StockTransfer).getInvoice();
if (!invoice || !invoice.name) { if (!invoice || !invoice.name) {
return; return;
} }

View File

@ -15,26 +15,6 @@
"default": "SQUOT-", "default": "SQUOT-",
"section": "Default" "section": "Default"
}, },
{
"fieldname": "account",
"drop": true
},
{
"fieldname": "stockNotTransferred",
"drop": true
},
{
"fieldname": "backReference",
"drop": true
},
{
"fieldname": "makeAutoStockTransfer",
"drop": true
},
{
"fieldname": "returnAgainst",
"drop": true
},
{ {
"fieldname": "party", "fieldname": "party",
"label": "Customer", "label": "Customer",
@ -54,5 +34,13 @@
"section": "Items" "section": "Items"
} }
], ],
"keywordFields": ["name", "party"] "keywordFields": ["name", "party"],
"removeFields": [
"account",
"stockNotTransferred",
"backReference",
"makeAutoStockTransfer",
"returnAgainst",
"isReturned"
]
} }

View File

@ -197,12 +197,8 @@ function getCombined(
const combined = Object.assign(abstractSchema, extendingSchema); const combined = Object.assign(abstractSchema, extendingSchema);
for (const fieldname in extendingFields) { for (const fieldname in extendingFields) {
if (extendingFields[fieldname].drop) {
delete abstractFields[fieldname]
} else {
abstractFields[fieldname] = extendingFields[fieldname]; abstractFields[fieldname] = extendingFields[fieldname];
} }
}
combined.fields = getListFromMap(abstractFields); combined.fields = getListFromMap(abstractFields);
return combined; return combined;

View File

@ -4,9 +4,7 @@
<hr /> <hr />
<div class="p-4 w-full flex flex-col gap-4"> <div class="p-4 w-full flex flex-col gap-4">
<p class="text-base text-gray-900"> <p class="text-base text-gray-900">
{{ {{ t`Select the template type.` }}
t`Select the template type.`
}}
</p> </p>
<Select <Select
:df="df" :df="df"
@ -27,12 +25,10 @@
import { PrintTemplate } from 'models/baseModels/PrintTemplate'; import { PrintTemplate } from 'models/baseModels/PrintTemplate';
import { OptionField } from 'schemas/types'; import { OptionField } from 'schemas/types';
import Button from 'src/components/Button.vue'; import Button from 'src/components/Button.vue';
import Float from 'src/components/Controls/Float.vue';
import Select from 'src/components/Controls/Select.vue'; import Select from 'src/components/Controls/Select.vue';
import FormHeader from 'src/components/FormHeader.vue'; import FormHeader from 'src/components/FormHeader.vue';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
type SizeName = typeof printSizes[number];
export default defineComponent({ export default defineComponent({
components: { FormHeader, Select, Button }, components: { FormHeader, Select, Button },
props: { doc: { type: PrintTemplate, required: true } }, props: { doc: { type: PrintTemplate, required: true } },
@ -42,14 +38,14 @@ export default defineComponent({
}, },
computed: { computed: {
df(): OptionField { df(): OptionField {
const options = PrintTemplate.lists.type(this.doc) const options = PrintTemplate.lists.type(this.doc);
return { return {
...fyo.getField('PrintTemplate', 'type'), ...fyo.getField('PrintTemplate', 'type'),
options, options,
fieldtype: 'Select', fieldtype: 'Select',
default: options[0].value default: options[0].value,
} } as OptionField;
} },
}, },
mounted() { mounted() {
this.type = this.doc.type ?? 'SalesInvoice'; this.type = this.doc.type ?? 'SalesInvoice';

View File

@ -204,7 +204,7 @@ async function getPrintTemplateDocValues(doc: Doc, fieldnames?: string[]) {
values[fieldname] = table; values[fieldname] = table;
} }
values.submitted = doc.submitted values.submitted = doc.submitted;
values.entryType = doc.schema.name; values.entryType = doc.schema.name;
values.entryLabel = doc.schema.label; values.entryLabel = doc.schema.label;
@ -364,12 +364,14 @@ function getNameAndTypeFromTemplateFile(
return [{ name: `${name} - ${label}`, type: schemaName }]; return [{ name: `${name} - ${label}`, type: schemaName }];
} }
return [ModelNameEnum.SalesInvoice, ModelNameEnum.SalesQuote, ModelNameEnum.PurchaseInvoice].map( return [
(schemaName) => { ModelNameEnum.SalesInvoice,
ModelNameEnum.SalesQuote,
ModelNameEnum.PurchaseInvoice,
].map((schemaName) => {
const label = fyo.schemaMap[schemaName]?.label ?? schemaName; const label = fyo.schemaMap[schemaName]?.label ?? schemaName;
return { name: `${name} - ${label}`, type: schemaName }; return { name: `${name} - ${label}`, type: schemaName };
} });
);
} }
export const baseTemplate = `<main class="h-full w-full bg-white"> export const baseTemplate = `<main class="h-full w-full bg-white">