Skip to content

Commit

Permalink
chore: validate and lint typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
mildred committed Dec 22, 2023
1 parent 2a3540a commit c441744
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 85 deletions.
39 changes: 22 additions & 17 deletions models/baseModels/Invoice/Invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import { TaxSummary } from '../TaxSummary/TaxSummary';
import { ReturnDocItem } from 'models/inventory/types';
import { AccountFieldEnum, PaymentTypeEnum } from '../Payment/types';

export type TaxDetail = { account: string, payment_account?: string, rate: number };
export type TaxDetail = {
account: string;
payment_account?: string;
rate: number;
};

export type InvoiceTaxItem = {
details: TaxDetail,
exchangeRate?: number,
fullAmount: Money,
taxAmount: Money
}
details: TaxDetail;
exchangeRate?: number;
fullAmount: Money;
taxAmount: Money;
};

export abstract class Invoice extends Transactional {
_taxes: Record<string, Tax> = {};
Expand Down Expand Up @@ -67,7 +71,9 @@ export abstract class Invoice extends Transactional {
returnAgainst?: string;

get isSales() {
return this.schemaName === 'SalesInvoice' || this.schemaName == 'SalesQuote';
return (
this.schemaName === 'SalesInvoice' || this.schemaName == 'SalesQuote'
);
}

get isQuote() {
Expand Down Expand Up @@ -256,15 +262,14 @@ export abstract class Invoice extends Transactional {
}

async getTaxItems(): Promise<InvoiceTaxItem[]> {
const taxItems: InvoiceTaxItem[] = []
const taxItems: InvoiceTaxItem[] = [];
for (const item of this.items ?? []) {
if (!item.tax) {
continue;
}

const tax = await this.getTax(item.tax);
for (const details of (tax.details ?? []) as TaxDetail[]) {

let amount = item.amount!;
if (
this.enableDiscounting &&
Expand All @@ -274,18 +279,18 @@ export abstract class Invoice extends Transactional {
amount = item.itemDiscountedTotal!;
}

let taxItem: InvoiceTaxItem = {
const taxItem: InvoiceTaxItem = {
details,
exchangeRate: this.exchangeRate ?? 1,
fullAmount: amount,
taxAmount: amount.mul(details.rate / 100)
}
taxAmount: amount.mul(details.rate / 100),
};

taxItems.push(taxItem)
taxItems.push(taxItem);
}
}

return taxItems
return taxItems;
}

async getTaxSummary() {
Expand All @@ -298,14 +303,14 @@ export abstract class Invoice extends Transactional {
}
> = {};

for(const { details, taxAmount } of await this.getTaxItems()) {
const account = details.account
for (const { details, taxAmount } of await this.getTaxItems()) {
const account = details.account;

taxes[account] ??= {
account,
rate: details.rate,
amount: this.fyo.pesa(0),
}
};

taxes[account].amount = taxes[account].amount.add(taxAmount);
}
Expand Down
5 changes: 4 additions & 1 deletion models/baseModels/InvoiceItem/InvoiceItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export abstract class InvoiceItem extends Doc {
itemTaxedTotal?: Money;

get isSales() {
return this.schemaName === 'SalesInvoiceItem' || this.schemaName === 'SalesQuoteItem';
return (
this.schemaName === 'SalesInvoiceItem' ||
this.schemaName === 'SalesQuoteItem'
);
}

get date() {
Expand Down
28 changes: 17 additions & 11 deletions models/baseModels/Payment/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,27 @@ export class Payment extends Transactional {
continue;
}

for(const {details, taxAmount, exchangeRate} of await refDoc.getTaxItems()) {
const { account, payment_account } = details
for (const {
details,
taxAmount,
exchangeRate,
} of await refDoc.getTaxItems()) {
const { account, payment_account } = details;
if (!payment_account) {
continue
continue;
}

taxes[payment_account] ??= {}
taxes[payment_account] ??= {};
taxes[payment_account][account] ??= {
account: payment_account,
from_account: account,
rate: details.rate,
amount: this.fyo.pesa(0),
}
};

taxes[payment_account][account].amount = taxes[payment_account][account].amount.add(taxAmount.mul(exchangeRate ?? 1));
taxes[payment_account][account].amount = taxes[payment_account][
account
].amount.add(taxAmount.mul(exchangeRate ?? 1));
}
}

Expand Down Expand Up @@ -323,13 +329,13 @@ export class Payment extends Transactional {
if (this.taxes) {
if (this.paymentType === 'Receive') {
for (const tax of this.taxes) {
await posting.debit(tax.from_account!, tax.amount!)
await posting.credit(tax.account!, tax.amount!)
await posting.debit(tax.from_account!, tax.amount!);
await posting.credit(tax.account!, tax.amount!);
}
} else if (this.paymentType === 'Pay') {
} else if (this.paymentType === 'Pay') {
for (const tax of this.taxes) {
await posting.credit(tax.from_account!, tax.amount!)
await posting.debit(tax.account!, tax.amount!)
await posting.credit(tax.from_account!, tax.amount!);
await posting.debit(tax.account!, tax.amount!);
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions models/baseModels/SalesQuote/SalesQuote.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Fyo } from 'fyo';
import { DocValueMap } from 'fyo/core/types';
import { Action, ListViewSettings } from 'fyo/model/types';
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
import { ModelNameEnum } from 'models/types';
import { getQuoteActions, getTransactionStatusColumn } from '../../helpers';
import { Invoice } from '../Invoice/Invoice';
import { SalesQuoteItem } from '../SalesQuoteItem/SalesQuoteItem';
import { Defaults } from '../Defaults/Defaults';

export class SalesQuote extends Invoice {
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() {
return null;
}
Expand All @@ -23,20 +27,18 @@ export class SalesQuote extends Invoice {
const terms = defaults.salesInvoiceTerms ?? '';
const numberSeries = defaults.salesInvoiceNumberSeries ?? undefined;

const data = {
...this,
const data: DocValueMap = {
...this.getValidDict(false, true),
date: new Date().toISOString(),
terms,
numberSeries,
quote: this.name,
items: []
items: [],
};

const invoice = this.fyo.doc.getNewDoc(schemaName, data) as Invoice;
for (const row of this.items ?? []) {
await invoice.append('items', {
...row
});
await invoice.append('items', row.getValidDict(false, true));
}

if (!invoice.items?.length) {
Expand Down
16 changes: 9 additions & 7 deletions models/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from './baseModels/Account/types';
import { numberSeriesDefaultsMap } from './baseModels/Defaults/Defaults';
import { Invoice } from './baseModels/Invoice/Invoice';
import { SalesQuote } from './baseModels/SalesQuote/SalesQuote';
import { StockMovement } from './inventory/StockMovement';
import { StockTransfer } from './inventory/StockTransfer';
import { InvoiceStatus, ModelNameEnum } from './types';
Expand All @@ -19,9 +20,7 @@ export function getQuoteActions(
fyo: Fyo,
schemaName: ModelNameEnum.SalesQuote
): Action[] {
return [
getMakeInvoiceAction(fyo, schemaName),
];
return [getMakeInvoiceAction(fyo, schemaName)];
}

export function getInvoiceActions(
Expand Down Expand Up @@ -76,7 +75,10 @@ export function getMakeStockTransferAction(

export function getMakeInvoiceAction(
fyo: Fyo,
schemaName: ModelNameEnum.Shipment | ModelNameEnum.PurchaseReceipt | ModelNameEnum.SalesQuote
schemaName:
| ModelNameEnum.Shipment
| ModelNameEnum.PurchaseReceipt
| ModelNameEnum.SalesQuote
): Action {
let label = fyo.t`Sales Invoice`;
if (schemaName === ModelNameEnum.PurchaseReceipt) {
Expand All @@ -88,13 +90,13 @@ export function getMakeInvoiceAction(
group: fyo.t`Create`,
condition: (doc: Doc) => {
if (schemaName === ModelNameEnum.SalesQuote) {
return doc.isSubmitted
return doc.isSubmitted;
} else {
return doc.isSubmitted && !doc.backReference
return doc.isSubmitted && !doc.backReference;
}
},
action: async (doc: Doc) => {
let invoice = await (doc as SalesQuote | StockTransfer).getInvoice();
const invoice = await (doc as SalesQuote | StockTransfer).getInvoice();
if (!invoice || !invoice.name) {
return;
}
Expand Down
23 changes: 2 additions & 21 deletions schemas/app/SalesQuote.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@
"default": "SQUOT-",
"section": "Default"
},
{
"fieldname": "account",
"drop": true
},
{
"fieldname": "stockNotTransferred",
"drop": true
},
{
"fieldname": "backReference",
"drop": true
},
{
"fieldname": "makeAutoStockTransfer",
"drop": true
},
{
"fieldname": "returnAgainst",
"drop": true
},
{
"fieldname": "party",
"label": "Customer",
Expand All @@ -54,5 +34,6 @@
"section": "Items"
}
],
"keywordFields": ["name", "party"]
"keywordFields": ["name", "party"],
"removeFields": ["account", "stockNotTransferred", "backReference", "makeAutoStockTransfer", "returnAgainst", "isReturned"]
}
6 changes: 1 addition & 5 deletions schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ function getCombined(
const combined = Object.assign(abstractSchema, extendingSchema);

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);
Expand Down
14 changes: 5 additions & 9 deletions src/pages/TemplateBuilder/SetType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<hr />
<div class="p-4 w-full flex flex-col gap-4">
<p class="text-base text-gray-900">
{{
t`Select the template type.`
}}
{{ t`Select the template type.` }}
</p>
<Select
:df="df"
Expand All @@ -27,12 +25,10 @@
import { PrintTemplate } from 'models/baseModels/PrintTemplate';
import { OptionField } from 'schemas/types';
import Button from 'src/components/Button.vue';
import Float from 'src/components/Controls/Float.vue';
import Select from 'src/components/Controls/Select.vue';
import FormHeader from 'src/components/FormHeader.vue';
import { defineComponent } from 'vue';
type SizeName = typeof printSizes[number];
export default defineComponent({
components: { FormHeader, Select, Button },
props: { doc: { type: PrintTemplate, required: true } },
Expand All @@ -42,14 +38,14 @@ export default defineComponent({
},
computed: {
df(): OptionField {
const options = PrintTemplate.lists.type(this.doc)
const options = PrintTemplate.lists.type(this.doc);
return {
...fyo.getField('PrintTemplate', 'type'),
options,
fieldtype: 'Select',
default: options[0].value
}
}
default: options[0].value,
} as OptionField;
},
},
mounted() {
this.type = this.doc.type ?? 'SalesInvoice';
Expand Down
16 changes: 9 additions & 7 deletions src/utils/printTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function getPrintTemplateDocValues(doc: Doc, fieldnames?: string[]) {
values[fieldname] = table;
}

values.submitted = doc.submitted
values.submitted = doc.submitted;
values.entryType = doc.schema.name;
values.entryLabel = doc.schema.label;

Expand Down Expand Up @@ -364,12 +364,14 @@ function getNameAndTypeFromTemplateFile(
return [{ name: `${name} - ${label}`, type: schemaName }];
}

return [ModelNameEnum.SalesInvoice, ModelNameEnum.SalesQuote, ModelNameEnum.PurchaseInvoice].map(
(schemaName) => {
const label = fyo.schemaMap[schemaName]?.label ?? schemaName;
return { name: `${name} - ${label}`, type: schemaName };
}
);
return [
ModelNameEnum.SalesInvoice,
ModelNameEnum.SalesQuote,
ModelNameEnum.PurchaseInvoice,
].map((schemaName) => {
const label = fyo.schemaMap[schemaName]?.label ?? schemaName;
return { name: `${name} - ${label}`, type: schemaName };
});
}

export const baseTemplate = `<main class="h-full w-full bg-white">
Expand Down

0 comments on commit c441744

Please sign in to comment.