From cb54100db49cc1b86285725bc186b55052115a8e Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 11 Apr 2022 15:11:49 +0530 Subject: [PATCH] incr: convert simple models to .ts Doc subclass --- frappe/model/doc.ts | 9 ++ frappe/model/types.ts | 37 ++++- models/baseModels/Account/Account.ts | 50 ++++++ .../AccountingLedgerEntry.ts | 8 + .../AccountingSettings/AccountingSettings.ts | 20 +++ .../Address/Address.js | 0 .../Address/RegionalChanges.js | 0 models/{doctype => baseModels}/Item/Item.js | 0 .../{doctype => baseModels}/Item/ItemList.js | 0 .../Item/RegionalChanges.js | 0 .../JournalEntry/JournalEntry.js | 0 .../JournalEntry/JournalEntryList.js | 0 .../JournalEntry/JournalEntryServer.js | 0 .../JournalEntryAccount.ts | 35 ++++ .../{doctype => baseModels}/Party/Customer.js | 0 .../Party/CustomerList.js | 0 models/{doctype => baseModels}/Party/Party.js | 0 .../Party/PartyList.js | 0 .../Party/PartyServer.js | 0 .../Party/PartyWidget.vue | 0 .../Party/RegionalChanges.js | 0 .../{doctype => baseModels}/Party/Supplier.js | 0 .../Party/SupplierList.js | 0 .../Payment/Payment.js | 0 .../Payment/PaymentList.js | 0 .../Payment/PaymentServer.js | 0 models/baseModels/PaymentFor/PaymentFor.ts | 28 ++++ .../PurchaseInvoice/PurchaseInvoice.js | 0 .../PurchaseInvoiceDocument.js | 0 .../PurchaseInvoice/PurchaseInvoiceList.js | 0 .../PurchaseInvoice/PurchaseInvoiceServer.js | 0 .../PurchaseInvoiceItem.js | 0 .../PurchaseInvoiceItem/RegionalChanges.js | 0 .../SalesInvoice/InvoiceTemplate.vue | 0 .../SalesInvoice/SalesInvoice.js | 0 .../SalesInvoice/SalesInvoiceDocument.js | 0 .../SalesInvoice/SalesInvoiceList.js | 0 .../SalesInvoice/SalesInvoicePrint.vue | 0 .../SalesInvoice/SalesInvoiceServer.js | 0 .../SalesInvoice/Templates/Base.vue | 0 .../SalesInvoice/Templates/Basic.vue | 0 .../SalesInvoice/Templates/Business.vue | 0 .../SalesInvoice/Templates/Minimal.vue | 0 .../SalesInvoiceItem/RegionalChanges.js | 0 .../SalesInvoiceItem/SalesInvoiceItem.js | 0 models/baseModels/SetupWizard/SetupWizard.ts | 95 +++++++++++ .../Tax/RegionalEntries.js | 0 models/{doctype => baseModels}/Tax/Tax.js | 0 models/{doctype => baseModels}/Tax/TaxList.js | 0 .../{doctype => baseModels}/Tax/TaxServer.js | 0 models/baseModels/TaxSummary/TaxSummary.ts | 13 ++ .../Transaction/Transaction.js | 0 .../Transaction/TransactionDocument.js | 0 .../Transaction/TransactionServer.js | 0 models/doctype/Account/Account.js | 95 ----------- models/doctype/Account/AccountDocument.js | 11 -- models/doctype/Account/AccountList.js | 7 - .../AccountingLedgerEntry.js | 85 ---------- .../AccountingLedgerEntryList.js | 7 - .../AccountingSettings/AccountingSettings.js | 129 --------------- models/doctype/Color/Color.js | 18 --- .../CompanySettings/CompanySettings.js | 27 ---- models/doctype/Contact/Contact.js | 78 --------- models/doctype/Currency/Currency.js | 38 ----- models/doctype/GetStarted/GetStarted.js | 67 -------- .../JournalEntryAccount.js | 45 ------ .../JournalEntrySettings.js | 10 -- models/doctype/PaymentFor/PaymentFor.js | 54 ------- .../PaymentSettings/PaymentSettings.js | 10 -- models/doctype/PrintSettings/PrintSettings.js | 105 ------------ .../PurchaseInvoiceSettings.js | 10 -- .../SalesInvoiceSettings.js | 37 ----- models/doctype/SetupWizard/SetupWizard.js | 150 ------------------ models/doctype/TaxDetail/TaxDetail.js | 26 --- models/doctype/TaxSummary/TaxSummary.js | 34 ---- utils/db/types.ts | 28 ++-- 76 files changed, 309 insertions(+), 1057 deletions(-) create mode 100644 models/baseModels/Account/Account.ts create mode 100644 models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts create mode 100644 models/baseModels/AccountingSettings/AccountingSettings.ts rename models/{doctype => baseModels}/Address/Address.js (100%) rename models/{doctype => baseModels}/Address/RegionalChanges.js (100%) rename models/{doctype => baseModels}/Item/Item.js (100%) rename models/{doctype => baseModels}/Item/ItemList.js (100%) rename models/{doctype => baseModels}/Item/RegionalChanges.js (100%) rename models/{doctype => baseModels}/JournalEntry/JournalEntry.js (100%) rename models/{doctype => baseModels}/JournalEntry/JournalEntryList.js (100%) rename models/{doctype => baseModels}/JournalEntry/JournalEntryServer.js (100%) create mode 100644 models/baseModels/JournalEntryAccount/JournalEntryAccount.ts rename models/{doctype => baseModels}/Party/Customer.js (100%) rename models/{doctype => baseModels}/Party/CustomerList.js (100%) rename models/{doctype => baseModels}/Party/Party.js (100%) rename models/{doctype => baseModels}/Party/PartyList.js (100%) rename models/{doctype => baseModels}/Party/PartyServer.js (100%) rename models/{doctype => baseModels}/Party/PartyWidget.vue (100%) rename models/{doctype => baseModels}/Party/RegionalChanges.js (100%) rename models/{doctype => baseModels}/Party/Supplier.js (100%) rename models/{doctype => baseModels}/Party/SupplierList.js (100%) rename models/{doctype => baseModels}/Payment/Payment.js (100%) rename models/{doctype => baseModels}/Payment/PaymentList.js (100%) rename models/{doctype => baseModels}/Payment/PaymentServer.js (100%) create mode 100644 models/baseModels/PaymentFor/PaymentFor.ts rename models/{doctype => baseModels}/PurchaseInvoice/PurchaseInvoice.js (100%) rename models/{doctype => baseModels}/PurchaseInvoice/PurchaseInvoiceDocument.js (100%) rename models/{doctype => baseModels}/PurchaseInvoice/PurchaseInvoiceList.js (100%) rename models/{doctype => baseModels}/PurchaseInvoice/PurchaseInvoiceServer.js (100%) rename models/{doctype => baseModels}/PurchaseInvoiceItem/PurchaseInvoiceItem.js (100%) rename models/{doctype => baseModels}/PurchaseInvoiceItem/RegionalChanges.js (100%) rename models/{doctype => baseModels}/SalesInvoice/InvoiceTemplate.vue (100%) rename models/{doctype => baseModels}/SalesInvoice/SalesInvoice.js (100%) rename models/{doctype => baseModels}/SalesInvoice/SalesInvoiceDocument.js (100%) rename models/{doctype => baseModels}/SalesInvoice/SalesInvoiceList.js (100%) rename models/{doctype => baseModels}/SalesInvoice/SalesInvoicePrint.vue (100%) rename models/{doctype => baseModels}/SalesInvoice/SalesInvoiceServer.js (100%) rename models/{doctype => baseModels}/SalesInvoice/Templates/Base.vue (100%) rename models/{doctype => baseModels}/SalesInvoice/Templates/Basic.vue (100%) rename models/{doctype => baseModels}/SalesInvoice/Templates/Business.vue (100%) rename models/{doctype => baseModels}/SalesInvoice/Templates/Minimal.vue (100%) rename models/{doctype => baseModels}/SalesInvoiceItem/RegionalChanges.js (100%) rename models/{doctype => baseModels}/SalesInvoiceItem/SalesInvoiceItem.js (100%) create mode 100644 models/baseModels/SetupWizard/SetupWizard.ts rename models/{doctype => baseModels}/Tax/RegionalEntries.js (100%) rename models/{doctype => baseModels}/Tax/Tax.js (100%) rename models/{doctype => baseModels}/Tax/TaxList.js (100%) rename models/{doctype => baseModels}/Tax/TaxServer.js (100%) create mode 100644 models/baseModels/TaxSummary/TaxSummary.ts rename models/{doctype => baseModels}/Transaction/Transaction.js (100%) rename models/{doctype => baseModels}/Transaction/TransactionDocument.js (100%) rename models/{doctype => baseModels}/Transaction/TransactionServer.js (100%) delete mode 100644 models/doctype/Account/Account.js delete mode 100644 models/doctype/Account/AccountDocument.js delete mode 100644 models/doctype/Account/AccountList.js delete mode 100644 models/doctype/AccountingLedgerEntry/AccountingLedgerEntry.js delete mode 100644 models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js delete mode 100644 models/doctype/AccountingSettings/AccountingSettings.js delete mode 100644 models/doctype/Color/Color.js delete mode 100644 models/doctype/CompanySettings/CompanySettings.js delete mode 100644 models/doctype/Contact/Contact.js delete mode 100644 models/doctype/Currency/Currency.js delete mode 100644 models/doctype/GetStarted/GetStarted.js delete mode 100644 models/doctype/JournalEntryAccount/JournalEntryAccount.js delete mode 100644 models/doctype/JournalEntrySettings/JournalEntrySettings.js delete mode 100644 models/doctype/PaymentFor/PaymentFor.js delete mode 100644 models/doctype/PaymentSettings/PaymentSettings.js delete mode 100644 models/doctype/PrintSettings/PrintSettings.js delete mode 100644 models/doctype/PurchaseInvoiceSettings/PurchaseInvoiceSettings.js delete mode 100644 models/doctype/SalesInvoiceSettings/SalesInvoiceSettings.js delete mode 100644 models/doctype/SetupWizard/SetupWizard.js delete mode 100644 models/doctype/TaxDetail/TaxDetail.js delete mode 100644 models/doctype/TaxSummary/TaxSummary.js diff --git a/frappe/model/doc.ts b/frappe/model/doc.ts index ddab7470..1ffd3e63 100644 --- a/frappe/model/doc.ts +++ b/frappe/model/doc.ts @@ -29,8 +29,12 @@ import { setName } from './naming'; import { DefaultMap, DependsOnMap, + FiltersMap, FormulaMap, + ListsMap, + ListViewSettings, RequiredMap, + TreeViewSettings, ValidationMap, } from './types'; import { validateSelect } from './validationFunction'; @@ -697,4 +701,9 @@ export default class Doc extends Observable { validations: ValidationMap = {}; required: RequiredMap = {}; dependsOn: DependsOnMap = {}; + + static lists: ListsMap = {}; + static filters: FiltersMap = {}; + static listSettings: ListViewSettings = {}; + static treeSettings?: TreeViewSettings; } diff --git a/frappe/model/types.ts b/frappe/model/types.ts index 894905e1..b86c06db 100644 --- a/frappe/model/types.ts +++ b/frappe/model/types.ts @@ -1,4 +1,6 @@ import { DocValue } from 'frappe/core/types'; +import { FieldType } from 'schemas/types'; +import { QueryFilter } from 'utils/db/types'; import Doc from './doc'; /** @@ -13,7 +15,7 @@ import Doc from './doc'; * - `Validation`: Async function that throw an error if the value is invalid. * - `Required`: Regular function used to decide if a value is mandatory (there are !notnul in the db). */ -export type Formula = () => Promise; +export type Formula = () => Promise; export type Default = () => DocValue; export type Validation = (value: DocValue) => Promise; export type Required = () => boolean; @@ -23,11 +25,38 @@ export type DefaultMap = Record; export type ValidationMap = Record; export type RequiredMap = Record; -export type DependsOnMap = Record +export type DependsOnMap = Record; /** * Should add this for hidden too */ -export type ModelMap = Record< string, typeof Doc | undefined> -export type DocMap = Record; \ No newline at end of file +export type ModelMap = Record; +export type DocMap = Record; + +// Static Config properties + +export type FilterFunction = (doc: Doc) => QueryFilter; +export type FiltersMap = Record; + +export type ListFunction = () => string[]; +export type ListsMap = Record; + +export interface ColumnConfig { + label: string; + fieldtype: FieldType; + size?: string; + render?: (doc: Doc) => { template: string }; + getValue?: (doc: Doc) => string; +} + +export type ListViewColumn = string | ColumnConfig; +export interface ListViewSettings { + formRoute?: (name: string) => string; + columns?: ListViewColumn[]; +} + +export interface TreeViewSettings { + parentField: string; + getRootLabel: () => Promise; +} diff --git a/models/baseModels/Account/Account.ts b/models/baseModels/Account/Account.ts new file mode 100644 index 00000000..e296306e --- /dev/null +++ b/models/baseModels/Account/Account.ts @@ -0,0 +1,50 @@ +import frappe from 'frappe'; +import Doc from 'frappe/model/doc'; +import { + FiltersMap, + ListViewSettings, + TreeViewSettings, +} from 'frappe/model/types'; +import { QueryFilter } from 'utils/db/types'; + +export default class Account extends Doc { + async beforeInsert() { + if (this.accountType || !this.parentAccount) { + return; + } + + const account = await frappe.db.get( + 'Account', + this.parentAccount as string + ); + this.accountType = account.accountType as string; + } + + static listSettings: ListViewSettings = { + columns: ['name', 'parentAccount', 'rootType'], + }; + + static treeSettings: TreeViewSettings = { + parentField: 'parentAccount', + async getRootLabel(): Promise { + const accountingSettings = await frappe.doc.getSingle( + 'AccountingSettings' + ); + return accountingSettings.companyName as string; + }, + }; + + static filters: FiltersMap = { + parentAccount: (doc: Doc) => { + const filter: QueryFilter = { + isGroup: true, + }; + + if (doc.rootType) { + filter.rootType = doc.rootType as string; + } + + return filter; + }, + }; +} diff --git a/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts new file mode 100644 index 00000000..b14e36e0 --- /dev/null +++ b/models/baseModels/AccountingLedgerEntry/AccountingLedgerEntry.ts @@ -0,0 +1,8 @@ +import Doc from 'frappe/model/doc'; +import { ListViewSettings } from 'frappe/model/types'; + +export class AccountingLedgerEntry extends Doc { + static listSettings: ListViewSettings = { + columns: ['account', 'party', 'debit', 'credit', 'balance'], + }; +} diff --git a/models/baseModels/AccountingSettings/AccountingSettings.ts b/models/baseModels/AccountingSettings/AccountingSettings.ts new file mode 100644 index 00000000..f6128e45 --- /dev/null +++ b/models/baseModels/AccountingSettings/AccountingSettings.ts @@ -0,0 +1,20 @@ +import Doc from 'frappe/model/doc'; +import { FiltersMap, ListsMap } from 'frappe/model/types'; +import countryInfo from '../../../fixtures/countryInfo.json'; + +export class AccountingSettings extends Doc { + static filters: FiltersMap = { + writeOffAccount: () => ({ + isGroup: false, + rootType: 'Expense', + }), + roundOffAccount: () => ({ + isGroup: false, + rootType: 'Expense', + }), + }; + + static lists: ListsMap = { + country: () => Object.keys(countryInfo), + }; +} diff --git a/models/doctype/Address/Address.js b/models/baseModels/Address/Address.js similarity index 100% rename from models/doctype/Address/Address.js rename to models/baseModels/Address/Address.js diff --git a/models/doctype/Address/RegionalChanges.js b/models/baseModels/Address/RegionalChanges.js similarity index 100% rename from models/doctype/Address/RegionalChanges.js rename to models/baseModels/Address/RegionalChanges.js diff --git a/models/doctype/Item/Item.js b/models/baseModels/Item/Item.js similarity index 100% rename from models/doctype/Item/Item.js rename to models/baseModels/Item/Item.js diff --git a/models/doctype/Item/ItemList.js b/models/baseModels/Item/ItemList.js similarity index 100% rename from models/doctype/Item/ItemList.js rename to models/baseModels/Item/ItemList.js diff --git a/models/doctype/Item/RegionalChanges.js b/models/baseModels/Item/RegionalChanges.js similarity index 100% rename from models/doctype/Item/RegionalChanges.js rename to models/baseModels/Item/RegionalChanges.js diff --git a/models/doctype/JournalEntry/JournalEntry.js b/models/baseModels/JournalEntry/JournalEntry.js similarity index 100% rename from models/doctype/JournalEntry/JournalEntry.js rename to models/baseModels/JournalEntry/JournalEntry.js diff --git a/models/doctype/JournalEntry/JournalEntryList.js b/models/baseModels/JournalEntry/JournalEntryList.js similarity index 100% rename from models/doctype/JournalEntry/JournalEntryList.js rename to models/baseModels/JournalEntry/JournalEntryList.js diff --git a/models/doctype/JournalEntry/JournalEntryServer.js b/models/baseModels/JournalEntry/JournalEntryServer.js similarity index 100% rename from models/doctype/JournalEntry/JournalEntryServer.js rename to models/baseModels/JournalEntry/JournalEntryServer.js diff --git a/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts b/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts new file mode 100644 index 00000000..99a5fe76 --- /dev/null +++ b/models/baseModels/JournalEntryAccount/JournalEntryAccount.ts @@ -0,0 +1,35 @@ +import frappe from 'frappe'; +import Doc from 'frappe/model/doc'; +import { FiltersMap, FormulaMap } from 'frappe/model/types'; +import Money from 'pesa/dist/types/src/money'; + +export class JournalEntryAccount extends Doc { + getAutoDebitCredit(type: 'debit' | 'credit') { + const otherType = type === 'debit' ? 'credit' : 'debit'; + + const otherTypeValue = this.get(otherType) as Money; + if (!otherTypeValue.isZero()) { + return frappe.pesa(0); + } + + const totalType = this.parentdoc!.getSum('accounts', type, false) as Money; + const totalOtherType = this.parentdoc!.getSum( + 'accounts', + otherType, + false + ) as Money; + + if (totalType.lt(totalOtherType)) { + return totalOtherType.sub(totalType); + } + } + + formulas: FormulaMap = { + debit: async () => this.getAutoDebitCredit('debit'), + credit: async () => this.getAutoDebitCredit('credit'), + }; + + static filters: FiltersMap = { + account: () => ({ isGroup: false }), + }; +} diff --git a/models/doctype/Party/Customer.js b/models/baseModels/Party/Customer.js similarity index 100% rename from models/doctype/Party/Customer.js rename to models/baseModels/Party/Customer.js diff --git a/models/doctype/Party/CustomerList.js b/models/baseModels/Party/CustomerList.js similarity index 100% rename from models/doctype/Party/CustomerList.js rename to models/baseModels/Party/CustomerList.js diff --git a/models/doctype/Party/Party.js b/models/baseModels/Party/Party.js similarity index 100% rename from models/doctype/Party/Party.js rename to models/baseModels/Party/Party.js diff --git a/models/doctype/Party/PartyList.js b/models/baseModels/Party/PartyList.js similarity index 100% rename from models/doctype/Party/PartyList.js rename to models/baseModels/Party/PartyList.js diff --git a/models/doctype/Party/PartyServer.js b/models/baseModels/Party/PartyServer.js similarity index 100% rename from models/doctype/Party/PartyServer.js rename to models/baseModels/Party/PartyServer.js diff --git a/models/doctype/Party/PartyWidget.vue b/models/baseModels/Party/PartyWidget.vue similarity index 100% rename from models/doctype/Party/PartyWidget.vue rename to models/baseModels/Party/PartyWidget.vue diff --git a/models/doctype/Party/RegionalChanges.js b/models/baseModels/Party/RegionalChanges.js similarity index 100% rename from models/doctype/Party/RegionalChanges.js rename to models/baseModels/Party/RegionalChanges.js diff --git a/models/doctype/Party/Supplier.js b/models/baseModels/Party/Supplier.js similarity index 100% rename from models/doctype/Party/Supplier.js rename to models/baseModels/Party/Supplier.js diff --git a/models/doctype/Party/SupplierList.js b/models/baseModels/Party/SupplierList.js similarity index 100% rename from models/doctype/Party/SupplierList.js rename to models/baseModels/Party/SupplierList.js diff --git a/models/doctype/Payment/Payment.js b/models/baseModels/Payment/Payment.js similarity index 100% rename from models/doctype/Payment/Payment.js rename to models/baseModels/Payment/Payment.js diff --git a/models/doctype/Payment/PaymentList.js b/models/baseModels/Payment/PaymentList.js similarity index 100% rename from models/doctype/Payment/PaymentList.js rename to models/baseModels/Payment/PaymentList.js diff --git a/models/doctype/Payment/PaymentServer.js b/models/baseModels/Payment/PaymentServer.js similarity index 100% rename from models/doctype/Payment/PaymentServer.js rename to models/baseModels/Payment/PaymentServer.js diff --git a/models/baseModels/PaymentFor/PaymentFor.ts b/models/baseModels/PaymentFor/PaymentFor.ts new file mode 100644 index 00000000..608389fe --- /dev/null +++ b/models/baseModels/PaymentFor/PaymentFor.ts @@ -0,0 +1,28 @@ +import frappe from 'frappe'; +import Doc from 'frappe/model/doc'; +import { FiltersMap, FormulaMap } from 'frappe/model/types'; +import Money from 'pesa/dist/types/src/money'; + +export class PaymentFor extends Doc { + formulas: FormulaMap = { + amount: async () => { + const outstandingAmount = this.parentdoc!.getFrom( + this.referenceType as string, + this.referenceName as string, + 'outstandingAmount' + ) as Money; + + if (outstandingAmount) { + return outstandingAmount; + } + + return frappe.pesa(0); + }, + }; + + static filters: FiltersMap = { + referenceName: () => ({ + outstandingAmount: ['>', 0], + }), + }; +} diff --git a/models/doctype/PurchaseInvoice/PurchaseInvoice.js b/models/baseModels/PurchaseInvoice/PurchaseInvoice.js similarity index 100% rename from models/doctype/PurchaseInvoice/PurchaseInvoice.js rename to models/baseModels/PurchaseInvoice/PurchaseInvoice.js diff --git a/models/doctype/PurchaseInvoice/PurchaseInvoiceDocument.js b/models/baseModels/PurchaseInvoice/PurchaseInvoiceDocument.js similarity index 100% rename from models/doctype/PurchaseInvoice/PurchaseInvoiceDocument.js rename to models/baseModels/PurchaseInvoice/PurchaseInvoiceDocument.js diff --git a/models/doctype/PurchaseInvoice/PurchaseInvoiceList.js b/models/baseModels/PurchaseInvoice/PurchaseInvoiceList.js similarity index 100% rename from models/doctype/PurchaseInvoice/PurchaseInvoiceList.js rename to models/baseModels/PurchaseInvoice/PurchaseInvoiceList.js diff --git a/models/doctype/PurchaseInvoice/PurchaseInvoiceServer.js b/models/baseModels/PurchaseInvoice/PurchaseInvoiceServer.js similarity index 100% rename from models/doctype/PurchaseInvoice/PurchaseInvoiceServer.js rename to models/baseModels/PurchaseInvoice/PurchaseInvoiceServer.js diff --git a/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js b/models/baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem.js similarity index 100% rename from models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js rename to models/baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem.js diff --git a/models/doctype/PurchaseInvoiceItem/RegionalChanges.js b/models/baseModels/PurchaseInvoiceItem/RegionalChanges.js similarity index 100% rename from models/doctype/PurchaseInvoiceItem/RegionalChanges.js rename to models/baseModels/PurchaseInvoiceItem/RegionalChanges.js diff --git a/models/doctype/SalesInvoice/InvoiceTemplate.vue b/models/baseModels/SalesInvoice/InvoiceTemplate.vue similarity index 100% rename from models/doctype/SalesInvoice/InvoiceTemplate.vue rename to models/baseModels/SalesInvoice/InvoiceTemplate.vue diff --git a/models/doctype/SalesInvoice/SalesInvoice.js b/models/baseModels/SalesInvoice/SalesInvoice.js similarity index 100% rename from models/doctype/SalesInvoice/SalesInvoice.js rename to models/baseModels/SalesInvoice/SalesInvoice.js diff --git a/models/doctype/SalesInvoice/SalesInvoiceDocument.js b/models/baseModels/SalesInvoice/SalesInvoiceDocument.js similarity index 100% rename from models/doctype/SalesInvoice/SalesInvoiceDocument.js rename to models/baseModels/SalesInvoice/SalesInvoiceDocument.js diff --git a/models/doctype/SalesInvoice/SalesInvoiceList.js b/models/baseModels/SalesInvoice/SalesInvoiceList.js similarity index 100% rename from models/doctype/SalesInvoice/SalesInvoiceList.js rename to models/baseModels/SalesInvoice/SalesInvoiceList.js diff --git a/models/doctype/SalesInvoice/SalesInvoicePrint.vue b/models/baseModels/SalesInvoice/SalesInvoicePrint.vue similarity index 100% rename from models/doctype/SalesInvoice/SalesInvoicePrint.vue rename to models/baseModels/SalesInvoice/SalesInvoicePrint.vue diff --git a/models/doctype/SalesInvoice/SalesInvoiceServer.js b/models/baseModels/SalesInvoice/SalesInvoiceServer.js similarity index 100% rename from models/doctype/SalesInvoice/SalesInvoiceServer.js rename to models/baseModels/SalesInvoice/SalesInvoiceServer.js diff --git a/models/doctype/SalesInvoice/Templates/Base.vue b/models/baseModels/SalesInvoice/Templates/Base.vue similarity index 100% rename from models/doctype/SalesInvoice/Templates/Base.vue rename to models/baseModels/SalesInvoice/Templates/Base.vue diff --git a/models/doctype/SalesInvoice/Templates/Basic.vue b/models/baseModels/SalesInvoice/Templates/Basic.vue similarity index 100% rename from models/doctype/SalesInvoice/Templates/Basic.vue rename to models/baseModels/SalesInvoice/Templates/Basic.vue diff --git a/models/doctype/SalesInvoice/Templates/Business.vue b/models/baseModels/SalesInvoice/Templates/Business.vue similarity index 100% rename from models/doctype/SalesInvoice/Templates/Business.vue rename to models/baseModels/SalesInvoice/Templates/Business.vue diff --git a/models/doctype/SalesInvoice/Templates/Minimal.vue b/models/baseModels/SalesInvoice/Templates/Minimal.vue similarity index 100% rename from models/doctype/SalesInvoice/Templates/Minimal.vue rename to models/baseModels/SalesInvoice/Templates/Minimal.vue diff --git a/models/doctype/SalesInvoiceItem/RegionalChanges.js b/models/baseModels/SalesInvoiceItem/RegionalChanges.js similarity index 100% rename from models/doctype/SalesInvoiceItem/RegionalChanges.js rename to models/baseModels/SalesInvoiceItem/RegionalChanges.js diff --git a/models/doctype/SalesInvoiceItem/SalesInvoiceItem.js b/models/baseModels/SalesInvoiceItem/SalesInvoiceItem.js similarity index 100% rename from models/doctype/SalesInvoiceItem/SalesInvoiceItem.js rename to models/baseModels/SalesInvoiceItem/SalesInvoiceItem.js diff --git a/models/baseModels/SetupWizard/SetupWizard.ts b/models/baseModels/SetupWizard/SetupWizard.ts new file mode 100644 index 00000000..3728b2f3 --- /dev/null +++ b/models/baseModels/SetupWizard/SetupWizard.ts @@ -0,0 +1,95 @@ +import frappe from 'frappe'; +import Doc from 'frappe/model/doc'; +import { FormulaMap, ListsMap } from 'frappe/model/types'; +import { DateTime } from 'luxon'; +import countryInfo from '../../../fixtures/countryInfo.json'; + +export function getCOAList() { + return [ + { name: frappe.t`Standard Chart of Accounts`, countryCode: '' }, + + { countryCode: 'ae', name: 'U.A.E - Chart of Accounts' }, + { + countryCode: 'ca', + name: 'Canada - Plan comptable pour les provinces francophones', + }, + { countryCode: 'gt', name: 'Guatemala - Cuentas' }, + { countryCode: 'hu', name: 'Hungary - Chart of Accounts' }, + { countryCode: 'id', name: 'Indonesia - Chart of Accounts' }, + { countryCode: 'in', name: 'India - Chart of Accounts' }, + { countryCode: 'mx', name: 'Mexico - Plan de Cuentas' }, + { countryCode: 'ni', name: 'Nicaragua - Catalogo de Cuentas' }, + { countryCode: 'nl', name: 'Netherlands - Grootboekschema' }, + { countryCode: 'sg', name: 'Singapore - Chart of Accounts' }, + ]; +} + +export class SetupWizard extends Doc { + formulas: FormulaMap = { + fiscalYearStart: async () => { + if (!this.country) return; + + const today = DateTime.local(); + + // @ts-ignore + const fyStart = countryInfo[this.country].fiscal_year_start as + | string + | undefined; + + if (fyStart) { + return DateTime.fromFormat(fyStart, 'MM-dd') + .plus({ year: [1, 2, 3].includes(today.month) ? -1 : 0 }) + .toISODate(); + } + }, + fiscalYearEnd: async () => { + if (!this.country) { + return; + } + + const today = DateTime.local(); + + // @ts-ignore + const fyEnd = countryInfo[this.country].fiscal_year_end as + | string + | undefined; + if (fyEnd) { + return DateTime.fromFormat(fyEnd, 'MM-dd') + .plus({ year: [1, 2, 3].includes(today.month) ? 0 : 1 }) + .toISODate(); + } + }, + currency: async () => { + if (!this.country) { + return; + } + // @ts-ignore + return countryInfo[this.country].currency; + }, + chartOfAccounts: async () => { + const country = this.get('country') as string | undefined; + if (country === undefined) { + return; + } + + // @ts-ignore + const code = (countryInfo[country] as undefined | { code: string })?.code; + if (code === undefined) { + return; + } + + const coaList = getCOAList(); + const coa = coaList.find(({ countryCode }) => countryCode === code); + + if (coa === undefined) { + return coaList[0].name; + } + return coa.name; + }, + }; + + static lists: ListsMap = { + country: () => Object.keys(countryInfo), + chartOfAccounts: () => getCOAList().map(({ name }) => name), + }; +} diff --git a/models/doctype/Tax/RegionalEntries.js b/models/baseModels/Tax/RegionalEntries.js similarity index 100% rename from models/doctype/Tax/RegionalEntries.js rename to models/baseModels/Tax/RegionalEntries.js diff --git a/models/doctype/Tax/Tax.js b/models/baseModels/Tax/Tax.js similarity index 100% rename from models/doctype/Tax/Tax.js rename to models/baseModels/Tax/Tax.js diff --git a/models/doctype/Tax/TaxList.js b/models/baseModels/Tax/TaxList.js similarity index 100% rename from models/doctype/Tax/TaxList.js rename to models/baseModels/Tax/TaxList.js diff --git a/models/doctype/Tax/TaxServer.js b/models/baseModels/Tax/TaxServer.js similarity index 100% rename from models/doctype/Tax/TaxServer.js rename to models/baseModels/Tax/TaxServer.js diff --git a/models/baseModels/TaxSummary/TaxSummary.ts b/models/baseModels/TaxSummary/TaxSummary.ts new file mode 100644 index 00000000..3f5c4b0f --- /dev/null +++ b/models/baseModels/TaxSummary/TaxSummary.ts @@ -0,0 +1,13 @@ +import Doc from 'frappe/model/doc'; +import { FormulaMap } from 'frappe/model/types'; +import Money from 'pesa/dist/types/src/money'; + +export class TaxSummary extends Doc { + formulas: FormulaMap = { + baseAmount: async () => { + const amount = this.amount as Money; + const exchangeRate = (this.parentdoc?.exchangeRate ?? 1) as number; + return amount.mul(exchangeRate); + }, + }; +} diff --git a/models/doctype/Transaction/Transaction.js b/models/baseModels/Transaction/Transaction.js similarity index 100% rename from models/doctype/Transaction/Transaction.js rename to models/baseModels/Transaction/Transaction.js diff --git a/models/doctype/Transaction/TransactionDocument.js b/models/baseModels/Transaction/TransactionDocument.js similarity index 100% rename from models/doctype/Transaction/TransactionDocument.js rename to models/baseModels/Transaction/TransactionDocument.js diff --git a/models/doctype/Transaction/TransactionServer.js b/models/baseModels/Transaction/TransactionServer.js similarity index 100% rename from models/doctype/Transaction/TransactionServer.js rename to models/baseModels/Transaction/TransactionServer.js diff --git a/models/doctype/Account/Account.js b/models/doctype/Account/Account.js deleted file mode 100644 index bee98c57..00000000 --- a/models/doctype/Account/Account.js +++ /dev/null @@ -1,95 +0,0 @@ -import frappe, { t } from 'frappe'; -import Account from './AccountDocument'; - -export default { - name: 'Account', - label: t`Account`, - doctype: 'DocType', - documentClass: Account, - isSingle: 0, - isTree: 1, - keywordFields: ['name', 'rootType', 'accountType'], - fields: [ - { - fieldname: 'name', - label: t`Account Name`, - fieldtype: 'Data', - required: 1, - }, - { - fieldname: 'rootType', - label: t`Root Type`, - fieldtype: 'Select', - placeholder: t`Root Type`, - options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'], - required: 1, - }, - { - fieldname: 'parentAccount', - label: t`Parent Account`, - fieldtype: 'Link', - target: 'Account', - getFilters: (query, doc) => { - const filter = { - isGroup: 1, - }; - doc.rootType ? (filter.rootType = doc.rootType) : ''; - return filter; - }, - }, - { - fieldname: 'accountType', - label: t`Account Type`, - placeholder: t`Account Type`, - fieldtype: 'Select', - options: [ - 'Accumulated Depreciation', - 'Bank', - 'Cash', - 'Chargeable', - 'Cost of Goods Sold', - 'Depreciation', - 'Equity', - 'Expense Account', - 'Expenses Included In Valuation', - 'Fixed Asset', - 'Income Account', - 'Payable', - 'Receivable', - 'Round Off', - 'Stock', - 'Stock Adjustment', - 'Stock Received But Not Billed', - 'Tax', - 'Temporary', - ], - }, - { - fieldname: 'balance', - label: t`Balance`, - fieldtype: 'Currency', - readOnly: 1, - }, - { - fieldname: 'isGroup', - label: t`Is Group`, - fieldtype: 'Check', - }, - ], - - quickEditFields: [ - 'name', - 'rootType', - 'parentAccount', - 'accountType', - 'isGroup', - ], - - treeSettings: { - parentField: 'parentAccount', - async getRootLabel() { - let accountingSettings = await frappe.getSingle('AccountingSettings'); - return accountingSettings.companyName; - }, - }, -}; diff --git a/models/doctype/Account/AccountDocument.js b/models/doctype/Account/AccountDocument.js deleted file mode 100644 index d83a7129..00000000 --- a/models/doctype/Account/AccountDocument.js +++ /dev/null @@ -1,11 +0,0 @@ -import frappe from 'frappe'; -import Document from 'frappe/model/document'; - -export default class Account extends Document { - async validate() { - if (!this.accountType && this.parentAccount) { - const account = frappe.db.get('Account', this.parentAccount); - this.accountType = account.accountType; - } - } -} diff --git a/models/doctype/Account/AccountList.js b/models/doctype/Account/AccountList.js deleted file mode 100644 index e7ecf690..00000000 --- a/models/doctype/Account/AccountList.js +++ /dev/null @@ -1,7 +0,0 @@ -import { t } from 'frappe'; - -export default { - doctype: 'Account', - title: t`Account`, - columns: ['name', 'parentAccount', 'rootType'], -}; diff --git a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntry.js b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntry.js deleted file mode 100644 index b82ceda8..00000000 --- a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntry.js +++ /dev/null @@ -1,85 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'AccountingLedgerEntry', - label: t`Ledger Entry`, - naming: 'autoincrement', - doctype: 'DocType', - isSingle: 0, - isChild: 0, - keywordFields: ['account', 'party', 'referenceName'], - fields: [ - { - fieldname: 'date', - label: t`Date`, - fieldtype: 'Date', - }, - { - fieldname: 'account', - label: t`Account`, - fieldtype: 'Link', - target: 'Account', - required: 1, - }, - { - fieldname: 'description', - label: t`Description`, - fieldtype: 'Text', - }, - { - fieldname: 'party', - label: t`Party`, - fieldtype: 'Link', - target: 'Party', - }, - { - fieldname: 'debit', - label: t`Debit`, - fieldtype: 'Currency', - }, - { - fieldname: 'credit', - label: t`Credit`, - fieldtype: 'Currency', - }, - { - fieldname: 'againstAccount', - label: t`Against Account`, - fieldtype: 'Text', - }, - { - fieldname: 'referenceType', - label: t`Ref. Type`, - fieldtype: 'Data', - }, - { - fieldname: 'referenceName', - label: t`Ref. Name`, - fieldtype: 'DynamicLink', - references: 'referenceType', - }, - { - fieldname: 'balance', - label: t`Balance`, - fieldtype: 'Currency', - }, - { - fieldname: 'reverted', - label: t`Reverted`, - fieldtype: 'Check', - default: 0, - }, - ], - quickEditFields: [ - 'date', - 'account', - 'description', - 'party', - 'debit', - 'credit', - 'againstAccount', - 'referenceType', - 'referenceName', - 'balance', - ], -}; diff --git a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js deleted file mode 100644 index 7d70814b..00000000 --- a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js +++ /dev/null @@ -1,7 +0,0 @@ -import { t } from 'frappe'; - -export default { - doctype: 'AccountingLedgerEntry', - title: t`Accounting Ledger Entries`, - columns: ['account', 'party', 'debit', 'credit', 'balance'], -}; diff --git a/models/doctype/AccountingSettings/AccountingSettings.js b/models/doctype/AccountingSettings/AccountingSettings.js deleted file mode 100644 index 5de9cc9a..00000000 --- a/models/doctype/AccountingSettings/AccountingSettings.js +++ /dev/null @@ -1,129 +0,0 @@ -import { t } from 'frappe'; -import countryInfo from '~/fixtures/countryInfo.json'; - -const countryList = Object.keys(countryInfo).sort(); -export default { - name: 'AccountingSettings', - label: t`Accounting Settings`, - naming: 'name', // {random|autoincrement} - isSingle: 1, - isChild: 0, - isSubmittable: 0, - settings: null, - keywordFields: [], - fields: [ - { - label: t`Company Name`, - fieldname: 'companyName', - fieldtype: 'Data', - required: 1, - }, - - { - label: t`Write Off Account`, - fieldname: 'writeOffAccount', - fieldtype: 'Link', - target: 'Account', - default: 'Write Off', - getFilters() { - return { - isGroup: 0, - rootType: 'Expense', - }; - }, - }, - - { - label: t`Round Off Account`, - fieldname: 'roundOffAccount', - fieldtype: 'Link', - target: 'Account', - default: 'Rounded Off', - getFilters() { - return { - isGroup: 0, - rootType: 'Expense', - }; - }, - }, - - { - fieldname: 'country', - label: t`Country`, - fieldtype: 'AutoComplete', - placeholder: t`Select Country`, - readOnly: 1, - required: 1, - getList: () => countryList, - }, - - { - fieldname: 'currency', - label: t`Currency`, - fieldtype: 'Data', - readOnly: 1, - required: 0, - }, - - { - fieldname: 'fullname', - label: t`Name`, - fieldtype: 'Data', - required: 1, - }, - - { - fieldname: 'email', - label: t`Email`, - fieldtype: 'Data', - required: 1, - validate: { - type: 'email', - }, - }, - - { - fieldname: 'bankName', - label: t`Bank Name`, - fieldtype: 'Data', - required: 1, - }, - - { - fieldname: 'fiscalYearStart', - label: t`Fiscal Year Start Date`, - fieldtype: 'Date', - required: 1, - }, - - { - fieldname: 'fiscalYearEnd', - label: t`Fiscal Year End Date`, - fieldtype: 'Date', - required: 1, - }, - - { - fieldname: 'setupComplete', - label: t`Setup Complete`, - fieldtype: 'Check', - default: 0, - }, - { - fieldname: 'gstin', - label: t`GSTIN`, - fieldtype: 'Data', - placeholder: t`27AAAAA0000A1Z5`, - }, - ], - quickEditFields: [ - 'fullname', - 'email', - 'companyName', - 'country', - 'currency', - 'fiscalYearStart', - 'fiscalYearEnd', - 'gstin', - ], -}; diff --git a/models/doctype/Color/Color.js b/models/doctype/Color/Color.js deleted file mode 100644 index 11250616..00000000 --- a/models/doctype/Color/Color.js +++ /dev/null @@ -1,18 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'Color', - doctype: 'DocType', - fields: [ - { - fieldname: 'name', - fieldtype: 'Data', - label: t`Color`, - }, - { - fieldname: 'hexvalue', - fieldtype: 'Data', - label: t`Hex Value`, - }, - ], -}; diff --git a/models/doctype/CompanySettings/CompanySettings.js b/models/doctype/CompanySettings/CompanySettings.js deleted file mode 100644 index d52fa316..00000000 --- a/models/doctype/CompanySettings/CompanySettings.js +++ /dev/null @@ -1,27 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'CompanySettings', - label: t`Company Settings`, - naming: 'autoincrement', - isSingle: true, - isChild: false, - keywordFields: ['companyName'], - fields: [ - { - fieldname: 'companyName', - label: t`Company Name`, - fieldtype: 'Data', - disabled: false, - required: true, - }, - { - fieldname: 'companyAddress', - label: t`Company Address`, - fieldtype: 'Link', - disabled: false, - required: true, - target: 'Address', - }, - ], -}; diff --git a/models/doctype/Contact/Contact.js b/models/doctype/Contact/Contact.js deleted file mode 100644 index b9fcb263..00000000 --- a/models/doctype/Contact/Contact.js +++ /dev/null @@ -1,78 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'Contact', - doctype: 'DocType', - isSingle: 0, - naming: 'autoincrement', - pageSettings: { - hideTitle: true, - }, - titleField: 'fullName', - keywordFields: ['fullName'], - fields: [ - { - fieldname: 'fullName', - label: t`Full Name`, - fieldtype: 'Data', - required: 1, - }, - { - fieldname: 'emailAddress', - label: t`Email Address`, - fieldtype: 'Data', - }, - { - fieldname: 'userId', - label: t`User ID`, - fieldtype: 'Link', - target: 'User', - hidden: 1, - }, - { - fieldname: 'status', - label: t`Status`, - fieldtype: 'Select', - options: ['Passive', 'Open', 'Replied'], - }, - { - fieldname: 'gender', - label: t`Gender`, - fieldtype: 'Select', - options: ['Male', 'Female', 'Gender'], - }, - { - fieldname: 'mobileNumber', - label: t`Mobile Number`, - fieldtype: 'Data', - }, - { - fieldname: 'phone', - label: t`Phone`, - fieldtype: 'Data', - }, - ], - - events: { - validate: (doc) => {}, - }, - - listSettings: { - getFields(list) { - return ['fullName']; - }, - getRowHTML(list, data) { - return `
${list.getNameHTML(data)}
`; - }, - }, - - layout: [ - // section 1 - { - columns: [ - { fields: ['fullName', 'emailAddress', 'userId', 'status'] }, - { fields: ['postalCode', 'gender', 'phone', 'mobileNumber'] }, - ], - }, - ], -}; diff --git a/models/doctype/Currency/Currency.js b/models/doctype/Currency/Currency.js deleted file mode 100644 index ef474632..00000000 --- a/models/doctype/Currency/Currency.js +++ /dev/null @@ -1,38 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'Currency', - label: t`Currency`, - doctype: 'DocType', - isSingle: 0, - keywordFields: ['name', 'symbol'], - quickEditFields: ['name', 'symbol'], - fields: [ - { - fieldname: 'name', - label: t`Currency Name`, - fieldtype: 'Data', - required: 1, - }, - { - fieldname: 'fraction', - label: t`Fraction`, - fieldtype: 'Data', - }, - { - fieldname: 'fractionUnits', - label: t`Fraction Units`, - fieldtype: 'Int', - }, - { - label: t`Smallest Currency Fraction Value`, - fieldname: 'smallestValue', - fieldtype: 'Currency', - }, - { - label: t`Symbol`, - fieldname: 'symbol', - fieldtype: 'Data', - }, - ], -}; diff --git a/models/doctype/GetStarted/GetStarted.js b/models/doctype/GetStarted/GetStarted.js deleted file mode 100644 index a0619e73..00000000 --- a/models/doctype/GetStarted/GetStarted.js +++ /dev/null @@ -1,67 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'GetStarted', - isSingle: 1, - fields: [ - { - fieldname: 'onboardingComplete', - label: t`Onboarding Complete`, - fieldtype: 'Check', - }, - { - fieldname: 'companySetup', - label: t`Company Setup`, - fieldtype: 'Check', - }, - { - fieldname: 'systemSetup', - label: t`System Setup`, - fieldtype: 'Check', - }, - { - fieldname: 'invoiceSetup', - label: t`Invoice Setup`, - fieldtype: 'Check', - }, - { - fieldname: 'itemCreated', - label: t`Item Created`, - fieldtype: 'Check', - }, - { - fieldname: 'customerCreated', - label: t`Customer Created`, - fieldtype: 'Check', - }, - { - fieldname: 'supplierCreated', - label: t`Supplier Created`, - fieldtype: 'Check', - }, - { - fieldname: 'invoiceCreated', - label: t`Invoice Created`, - fieldtype: 'Check', - }, - { - fieldname: 'billCreated', - label: t`Bill Created`, - fieldtype: 'Check', - }, - { - fieldname: 'chartOfAccountsReviewed', - label: t`Chart Of Accounts Reviewed`, - fieldtype: 'Check', - }, - { - fieldname: 'openingBalanceChecked', - label: t`Opening Balances`, - fieldtype: 'Check', - }, - { - fieldname: 'taxesAdded', - label: t`Add Taxes`, - fieldtype: 'Check', - }, - ], -}; diff --git a/models/doctype/JournalEntryAccount/JournalEntryAccount.js b/models/doctype/JournalEntryAccount/JournalEntryAccount.js deleted file mode 100644 index 244c27f9..00000000 --- a/models/doctype/JournalEntryAccount/JournalEntryAccount.js +++ /dev/null @@ -1,45 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'JournalEntryAccount', - isChild: 1, - fields: [ - { - fieldname: 'account', - label: t`Account`, - placeholder: t`Account`, - fieldtype: 'Link', - target: 'Account', - required: 1, - groupBy: 'rootType', - getFilters: () => ({ isGroup: 0 }), - }, - { - fieldname: 'debit', - label: t`Debit`, - fieldtype: 'Currency', - formula: autoDebitCredit('debit'), - }, - { - fieldname: 'credit', - label: t`Credit`, - fieldtype: 'Currency', - formula: autoDebitCredit('credit'), - }, - ], - tableFields: ['account', 'debit', 'credit'], -}; - -function autoDebitCredit(type) { - let otherType = type === 'debit' ? 'credit' : 'debit'; - - return (row, doc) => { - if (!row[otherType].isZero()) return frappe.pesa(0); - - let totalType = doc.getSum('accounts', type, false); - let totalOtherType = doc.getSum('accounts', otherType, false); - - if (totalType.lt(totalOtherType)) { - return totalOtherType.sub(totalType); - } - }; -} diff --git a/models/doctype/JournalEntrySettings/JournalEntrySettings.js b/models/doctype/JournalEntrySettings/JournalEntrySettings.js deleted file mode 100644 index 36f0ec3e..00000000 --- a/models/doctype/JournalEntrySettings/JournalEntrySettings.js +++ /dev/null @@ -1,10 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'JournalEntrySettings', - label: t`Journal Entry Setting`, - doctype: 'DocType', - isSingle: 1, - isChild: 0, - keywordFields: [], - fields: [], -}; diff --git a/models/doctype/PaymentFor/PaymentFor.js b/models/doctype/PaymentFor/PaymentFor.js deleted file mode 100644 index 96e9b173..00000000 --- a/models/doctype/PaymentFor/PaymentFor.js +++ /dev/null @@ -1,54 +0,0 @@ -import frappe, { t } from 'frappe'; - -const referenceTypeMap = { - SalesInvoice: t`Invoice`, - PurchaseInvoice: t`Bill`, -}; - -export default { - name: 'PaymentFor', - label: t`Payment For`, - isSingle: 0, - isChild: 1, - keywordFields: [], - tableFields: ['referenceType', 'referenceName', 'amount'], - fields: [ - { - fieldname: 'referenceType', - label: t`Reference Type`, - placeholder: t`Type`, - fieldtype: 'Select', - options: Object.keys(referenceTypeMap), - map: referenceTypeMap, - required: 1, - }, - { - fieldname: 'referenceName', - label: t`Reference Name`, - fieldtype: 'DynamicLink', - references: 'referenceType', - placeholder: t`Name`, - getFilters() { - return { - outstandingAmount: ['>', 0], - }; - }, - required: 1, - }, - { - fieldname: 'amount', - label: t`Allocated Amount`, - fieldtype: 'Currency', - formula: (row, doc) => { - return ( - doc.getFrom( - row.referenceType, - row.referenceName, - 'outstandingAmount' - ) || frappe.pesa(0) - ); - }, - required: 1, - }, - ], -}; diff --git a/models/doctype/PaymentSettings/PaymentSettings.js b/models/doctype/PaymentSettings/PaymentSettings.js deleted file mode 100644 index c71a9199..00000000 --- a/models/doctype/PaymentSettings/PaymentSettings.js +++ /dev/null @@ -1,10 +0,0 @@ -import { t } from 'frappe'; - -export default { - name: 'PaymentSettings', - label: t`Payment Settings`, - isSingle: 1, - isChild: 0, - keywordFields: [], - fields: [], -}; diff --git a/models/doctype/PrintSettings/PrintSettings.js b/models/doctype/PrintSettings/PrintSettings.js deleted file mode 100644 index 72210ed5..00000000 --- a/models/doctype/PrintSettings/PrintSettings.js +++ /dev/null @@ -1,105 +0,0 @@ -import theme from '@/theme'; -import { t } from 'frappe'; - -export default { - name: 'PrintSettings', - label: t`Print Settings`, - isSingle: 1, - fields: [ - { - fieldname: 'logo', - label: t`Logo`, - fieldtype: 'AttachImage', - }, - { - fieldname: 'companyName', - label: t`Company Name`, - fieldtype: 'Data', - }, - { - fieldname: 'email', - label: t`Email`, - fieldtype: 'Data', - placeholder: t`john@doe.com`, - validate: { - type: 'email', - }, - }, - { - fieldname: 'displayLogo', - label: t`Display Logo in Invoice`, - fieldtype: 'Check', - }, - { - fieldname: 'phone', - label: t`Phone`, - fieldtype: 'Data', - placeholder: t`9888900000`, - validate: { - type: 'phone', - }, - }, - { - fieldname: 'address', - label: t`Address`, - fieldtype: 'Link', - target: 'Address', - placeholder: t`Click to create`, - inline: true, - }, - { - fieldname: 'template', - label: t`Template`, - placeholder: t`Template`, - fieldtype: 'Select', - options: ['Basic', 'Minimal', 'Business'], - default: 'Basic', - }, - { - fieldname: 'color', - label: t`Color`, - placeholder: t`Select Color`, - fieldtype: 'Color', - colors: [ - 'red', - 'orange', - 'yellow', - 'green', - 'teal', - 'blue', - 'indigo', - 'purple', - 'pink', - ] - .map((color) => { - let label = color[0].toUpperCase() + color.slice(1); - return { - label, - value: theme.colors[color]['500'], - }; - }) - .concat({ - label: t`Black`, - value: theme.colors['black'], - }), - }, - { - fieldname: 'font', - label: t`Font`, - placeholder: t`Font`, - fieldtype: 'Select', - options: ['Inter', 'Times New Roman', 'Arial', 'Courier'], - default: 'Inter', - }, - ], - quickEditFields: [ - 'logo', - 'displayLogo', - 'template', - 'color', - 'font', - 'email', - 'phone', - 'address', - ], -}; diff --git a/models/doctype/PurchaseInvoiceSettings/PurchaseInvoiceSettings.js b/models/doctype/PurchaseInvoiceSettings/PurchaseInvoiceSettings.js deleted file mode 100644 index 6ff16278..00000000 --- a/models/doctype/PurchaseInvoiceSettings/PurchaseInvoiceSettings.js +++ /dev/null @@ -1,10 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'PurchaseInvoiceSettings', - label: t`Bills Settings`, - doctype: 'DocType', - isSingle: 1, - isChild: 0, - keywordFields: [], - fields: [], -}; diff --git a/models/doctype/SalesInvoiceSettings/SalesInvoiceSettings.js b/models/doctype/SalesInvoiceSettings/SalesInvoiceSettings.js deleted file mode 100644 index 7150f585..00000000 --- a/models/doctype/SalesInvoiceSettings/SalesInvoiceSettings.js +++ /dev/null @@ -1,37 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'SalesInvoiceSettings', - label: t`SalesInvoice Settings`, - doctype: 'DocType', - isSingle: 1, - isChild: 0, - keywordFields: [], - fields: [ - { - fieldname: 'template', - label: t`Template`, - placeholder: t`Template`, - fieldtype: 'Select', - options: ['Basic I', 'Basic II', 'Modern'], - required: 1, - default: 'Basic I', - }, - { - fieldname: 'font', - label: t`Font`, - placeholder: t`Font`, - fieldtype: 'Select', - options: ['Montserrat', 'Open Sans', 'Oxygen', 'Merriweather'], - required: 1, - default: 'Montserrat', - }, - { - fieldname: 'themeColor', - label: t`Theme Color`, - fieldtype: 'Data', - required: 1, - default: '#000000', - hidden: 1, - }, - ], -}; diff --git a/models/doctype/SetupWizard/SetupWizard.js b/models/doctype/SetupWizard/SetupWizard.js deleted file mode 100644 index fca8396e..00000000 --- a/models/doctype/SetupWizard/SetupWizard.js +++ /dev/null @@ -1,150 +0,0 @@ -import { t } from 'frappe'; -import { DateTime } from 'luxon'; -import countryList from '~/fixtures/countryInfo.json'; -import { getCOAList } from '../../../src/utils'; - -export default { - name: 'SetupWizard', - label: t`Setup Wizard`, - naming: 'name', - isSingle: 1, - isChild: 0, - isSubmittable: 0, - settings: null, - keywordFields: [], - fields: [ - { - fieldname: 'companyLogo', - label: t`Company Logo`, - fieldtype: 'AttachImage', - }, - { - fieldname: 'country', - label: t`Country`, - fieldtype: 'AutoComplete', - placeholder: t`Select Country`, - required: 1, - getList: () => Object.keys(countryList).sort(), - }, - - { - fieldname: 'fullname', - label: t`Your Name`, - fieldtype: 'Data', - placeholder: t`John Doe`, - required: 1, - }, - - { - fieldname: 'email', - label: t`Email`, - fieldtype: 'Data', - placeholder: t`john@doe.com`, - required: 1, - validate: { - type: 'email', - }, - }, - - { - fieldname: 'companyName', - label: t`Company Name`, - placeholder: t`Company Name`, - fieldtype: 'Data', - required: 1, - }, - - { - fieldname: 'bankName', - label: t`Bank Name`, - fieldtype: 'Data', - placeholder: t`Prime Bank`, - required: 1, - }, - - { - fieldname: 'fiscalYearStart', - label: t`Fiscal Year Start Date`, - placeholder: t`Fiscal Year Start Date`, - fieldtype: 'Date', - formulaDependsOn: ['country'], - formula: (doc) => { - if (!doc.country) return; - let today = DateTime.local(); - let fyStart = countryList[doc.country].fiscal_year_start; - if (fyStart) { - return DateTime.fromFormat(fyStart, 'MM-dd') - .plus({ year: [1, 2, 3].includes(today.month) ? -1 : 0 }) - .toISODate(); - } - }, - required: 1, - }, - - { - fieldname: 'fiscalYearEnd', - label: t`Fiscal Year End Date`, - placeholder: t`Fiscal Year End Date`, - fieldtype: 'Date', - formulaDependsOn: ['country'], - formula: (doc) => { - if (!doc.country) return; - let today = DateTime.local(); - let fyEnd = countryList[doc.country].fiscal_year_end; - if (fyEnd) { - return DateTime.fromFormat(fyEnd, 'MM-dd') - .plus({ year: [1, 2, 3].includes(today.month) ? 0 : 1 }) - .toISODate(); - } - }, - required: 1, - }, - { - fieldname: 'currency', - label: t`Currency`, - fieldtype: 'Data', - placeholder: t`Currency`, - formulaDependsOn: ['country'], - formula: (doc) => { - if (!doc.country) return; - return countryList[doc.country].currency; - }, - required: 1, - }, - { - fieldname: 'completed', - label: t`Completed`, - fieldtype: 'Check', - readonly: 1, - }, - { - fieldname: 'chartOfAccounts', - label: t`Chart of Accounts`, - fieldtype: 'AutoComplete', - placeholder: t`Select CoA`, - formulaDependsOn: ['country'], - formula: async (doc) => { - if (!doc.country) return; - - const { code } = countryList[doc.country]; - const coaList = getCOAList(); - const coa = coaList.find(({ countryCode }) => countryCode === code); - - if (coa === undefined) { - return coaList[0].name; - } - return coa.name; - }, - getList: () => getCOAList().map(({ name }) => name), - }, - ], - quickEditFields: [ - 'fullname', - 'bankName', - 'country', - 'currency', - 'chartOfAccounts', - 'fiscalYearStart', - 'fiscalYearEnd', - ], -}; diff --git a/models/doctype/TaxDetail/TaxDetail.js b/models/doctype/TaxDetail/TaxDetail.js deleted file mode 100644 index a4c7bcd1..00000000 --- a/models/doctype/TaxDetail/TaxDetail.js +++ /dev/null @@ -1,26 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'TaxDetail', - label: t`Tax Detail`, - doctype: 'DocType', - isSingle: 0, - isChild: 1, - keywordFields: [], - fields: [ - { - fieldname: 'account', - label: t`Tax Account`, - fieldtype: 'Link', - target: 'Account', - required: 1, - }, - { - fieldname: 'rate', - label: t`Rate`, - fieldtype: 'Float', - required: 1, - placeholder: t`0%`, - }, - ], - tableFields: ['account', 'rate'], -}; diff --git a/models/doctype/TaxSummary/TaxSummary.js b/models/doctype/TaxSummary/TaxSummary.js deleted file mode 100644 index 90897e0d..00000000 --- a/models/doctype/TaxSummary/TaxSummary.js +++ /dev/null @@ -1,34 +0,0 @@ -import { t } from 'frappe'; -export default { - name: 'TaxSummary', - doctype: 'DocType', - isChild: 1, - fields: [ - { - fieldname: 'account', - label: t`Tax Account`, - fieldtype: 'Link', - target: 'Account', - required: 1, - }, - { - fieldname: 'rate', - label: t`Rate`, - fieldtype: 'Float', - required: 1, - }, - { - fieldname: 'amount', - label: t`Amount`, - fieldtype: 'Currency', - required: 1, - }, - { - fieldname: 'baseAmount', - label: t`Amount (Company Currency)`, - fieldtype: 'Currency', - formula: (row, doc) => row.amount.mul(doc.exchangeRate), - readOnly: 1, - }, - ], -}; diff --git a/utils/db/types.ts b/utils/db/types.ts index 4937aade..f517273f 100644 --- a/utils/db/types.ts +++ b/utils/db/types.ts @@ -6,7 +6,7 @@ * match on both ends. */ -import { SchemaMap } from "schemas/types"; +import { SchemaMap } from 'schemas/types'; type UnknownMap = Record; export abstract class DatabaseBase { @@ -62,24 +62,32 @@ export interface GetAllOptions { order?: 'asc' | 'desc'; } -export type QueryFilter = Record; - +export type QueryFilter = Record< + string, + boolean | string | (string | number)[] +>; /** * DatabaseDemuxBase is an abstract class that ensures that the function signatures * match between the DatabaseManager and the DatabaseDemux. - * + * * This allows testing the frontend code while directly plugging in the DatabaseManager * and bypassing all the API and IPC calls. */ export abstract class DatabaseDemuxBase { - abstract getSchemaMap(): Promise | SchemaMap + abstract getSchemaMap(): Promise | SchemaMap; - abstract createNewDatabase(dbPath: string, countryCode?: string): Promise + abstract createNewDatabase( + dbPath: string, + countryCode?: string + ): Promise; - abstract connectToDatabase(dbPath: string, countryCode?: string): Promise + abstract connectToDatabase( + dbPath: string, + countryCode?: string + ): Promise; - abstract call(method: DatabaseMethod, ...args: unknown[]): Promise - - abstract callBespoke(method: string, ...args: unknown[]): Promise + abstract call(method: DatabaseMethod, ...args: unknown[]): Promise; + + abstract callBespoke(method: string, ...args: unknown[]): Promise; }