From cc09847337866330c2da164eb713cd454d9c4270 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Fri, 21 Jan 2022 02:27:29 +0530 Subject: [PATCH] =?UTF-8?q?refactor:=20rename=20imports,=20frappejs=20?= =?UTF-8?q?=E2=86=92=20frappe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accounting/gst.js | 4 +- accounting/importCOA.js | 2 +- accounting/ledgerPosting.js | 2 +- fixtures/standardCOA.js | 318 +++++++-------- frappe/backends/database.js | 6 +- frappe/backends/http.js | 131 +++--- frappe/backends/mysql.js | 382 ++++++++++-------- frappe/backends/sqlite.js | 2 +- frappe/common/errors.js | 6 +- frappe/common/index.js | 4 +- frappe/index.js | 4 +- frappe/model/document.js | 4 +- frappe/model/meta.js | 4 +- frappe/model/naming.js | 170 ++++---- frappe/model/runPatches.js | 2 +- .../NumberSeries/NumberSeriesDocument.js | 24 +- .../doctype/SystemSettings/SystemSettings.js | 2 +- frappe/models/doctype/ToDo/ToDo.js | 30 +- frappe/models/doctype/ToDo/ToDoList.js | 10 +- frappe/utils/format.js | 2 +- models/doctype/Account/Account.js | 2 +- models/doctype/Account/AccountDocument.js | 6 +- models/doctype/Account/AccountList.js | 4 +- .../AccountingLedgerEntryList.js | 12 +- models/doctype/Email/Email.js | 139 +++---- models/doctype/EmailAccount/EmailAccount.js | 109 +++-- models/doctype/Event/EventDocument.js | 11 +- models/doctype/Fulfillment/Fulfillment.js | 20 +- .../FulfillmentItem/FulfillmentItem.js | 4 +- .../FulfillmentSettings.js | 18 +- models/doctype/GSTR3B/GSTR3B.js | 2 +- models/doctype/GSTR3B/GSTR3BDocument.js | 22 +- models/doctype/GSTR3B/GSTR3BList.js | 4 +- models/doctype/Item/Item.js | 4 +- models/doctype/Item/ItemList.js | 11 +- .../doctype/JournalEntry/JournalEntryList.js | 12 +- .../JournalEntry/JournalEntryServer.js | 2 +- models/doctype/Party/Customer.js | 40 +- models/doctype/Party/CustomerList.js | 4 +- models/doctype/Party/Party.js | 4 +- models/doctype/Party/PartyList.js | 4 +- models/doctype/Party/PartyServer.js | 4 +- models/doctype/Party/PartyWidget.vue | 2 +- models/doctype/Party/Supplier.js | 40 +- models/doctype/Party/SupplierList.js | 4 +- models/doctype/Payment/Payment.js | 2 +- models/doctype/Payment/PaymentList.js | 10 +- models/doctype/Payment/PaymentServer.js | 4 +- models/doctype/PaymentFor/PaymentFor.js | 4 +- .../PurchaseInvoice/PurchaseInvoiceList.js | 8 +- models/doctype/PurchaseOrder/PurchaseOrder.js | 10 +- .../PurchaseOrderItem/PurchaseOrderItem.js | 4 +- .../PurchaseOrderSettings.js | 18 +- .../PurchaseReceipt/PurchaseReceipt.js | 20 +- .../PurchaseReceiptItem.js | 30 +- .../PurchaseReceiptSettings.js | 18 +- models/doctype/Quotation/Quotation.js | 10 +- models/doctype/QuotationItem/QuotationItem.js | 4 +- .../QuotationSettings/QuotationSettings.js | 18 +- .../doctype/SalesInvoice/SalesInvoiceList.js | 8 +- .../doctype/SalesInvoice/Templates/Base.vue | 2 +- models/doctype/SalesOrder/SalesOrder.js | 8 +- .../doctype/SalesOrderItem/SalesOrderItem.js | 4 +- .../SalesOrderSettings/SalesOrderSettings.js | 18 +- models/doctype/Tax/RegionalEntries.js | 2 +- models/doctype/Tax/TaxList.js | 4 +- models/doctype/Transaction/Transaction.js | 2 +- .../Transaction/TransactionDocument.js | 4 +- .../doctype/Transaction/TransactionServer.js | 6 +- models/regionalModelUpdates.js | 2 +- patches/0.0.3/makePaymentRefIdNullable.js | 2 +- patches/0.0.4/convertCurrencyToStrings.js | 2 +- .../AccountsReceivablePayable.js | 40 +- reports/BalanceSheet/BalanceSheet.js | 84 ++-- reports/BalanceSheet/viewConfig.js | 2 +- .../BankReconciliation/BankReconciliation.js | 10 +- .../BankReconciliationImport.js | 2 +- reports/Cashflow/Cashflow.js | 16 +- .../FinancialStatements.js | 2 +- reports/GeneralLedger/GeneralLedger.js | 2 +- reports/GoodsAndServiceTax/BaseGSTR.js | 2 +- reports/ProfitAndLoss/ProfitAndLoss.js | 29 +- reports/ProfitAndLoss/viewConfig.js | 4 +- reports/PurchaseRegister/PurchaseRegister.js | 12 +- reports/SalesRegister/SalesRegister.js | 12 +- reports/TrialBalance/TrialBalance.js | 7 +- reports/TrialBalance/viewConfig.js | 2 +- reports/commonExporter.js | 2 +- reports/index.js | 44 +- server/index.js | 18 +- server/postStart.js | 23 +- server/registerServerMethods.js | 6 +- src/App.vue | 2 +- src/components/Controls/AttachImage.vue | 2 +- src/components/Controls/Currency.vue | 2 +- src/components/Controls/Date.vue | 2 +- src/components/Controls/Link.vue | 2 +- src/components/Controls/Table.vue | 2 +- src/components/InvoiceCustomizer.vue | 2 +- src/components/MessageDialog.vue | 2 +- src/components/SearchBar.vue | 2 +- src/components/TwoColumnForm.vue | 2 +- src/initialization.js | 2 +- src/main.js | 6 +- src/migrate.js | 4 +- src/pages/ChartOfAccounts.vue | 2 +- src/pages/Dashboard/Cashflow.vue | 2 +- src/pages/Dashboard/Expenses.vue | 2 +- src/pages/Dashboard/ProfitAndLoss.vue | 2 +- src/pages/Dashboard/UnpaidInvoices.vue | 2 +- src/pages/Dashboard/getDatesAndPeriodicity.js | 20 +- src/pages/DataImport/index.vue | 6 +- src/pages/GetStarted.vue | 4 +- src/pages/InvoiceForm.vue | 2 +- src/pages/JournalEntryForm.vue | 2 +- src/pages/ListView/List.vue | 2 +- src/pages/ListView/ListCell.vue | 2 +- src/pages/ListView/ListView.vue | 4 +- src/pages/PrintView/PrintView.vue | 2 +- src/pages/QuickEditForm.vue | 4 +- src/pages/Report.vue | 2 +- src/pages/Settings/Settings.vue | 4 +- src/pages/Settings/TabGeneral.vue | 2 +- src/pages/Settings/TabInvoice.vue | 2 +- src/pages/Settings/TabSystem.vue | 2 +- src/pages/SetupWizard/SetupWizard.vue | 2 +- src/pages/SetupWizard/setupCompany.js | 4 +- src/saveHtmlAsPdf.js | 2 +- src/sidebarConfig.js | 6 +- src/utils.js | 4 +- tests/testInvoice.js | 4 +- vue.config.js | 2 +- 132 files changed, 1140 insertions(+), 1122 deletions(-) diff --git a/accounting/gst.js b/accounting/gst.js index 59c0823d..c3f8f9d0 100644 --- a/accounting/gst.js +++ b/accounting/gst.js @@ -1,6 +1,6 @@ import { showMessageDialog } from '@/utils'; -import frappe from 'frappejs'; -import { _ } from 'frappejs/utils'; +import frappe from 'frappe'; +import { _ } from 'frappe/utils'; import { DateTime } from 'luxon'; import { exportCsv, saveExportData } from '../reports/commonExporter'; import { getSavePath } from '../src/utils'; diff --git a/accounting/importCOA.js b/accounting/importCOA.js index 6404fde9..b38ec5e5 100644 --- a/accounting/importCOA.js +++ b/accounting/importCOA.js @@ -1,4 +1,4 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; import countries from '../fixtures/countryInfo.json'; import standardCOA from '../fixtures/verified/standardCOA.json'; const accountFields = ['accountType', 'accountNumber', 'rootType', 'isGroup']; diff --git a/accounting/ledgerPosting.js b/accounting/ledgerPosting.js index 4bd9c603..8a6b2870 100644 --- a/accounting/ledgerPosting.js +++ b/accounting/ledgerPosting.js @@ -1,4 +1,4 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; export default class LedgerPosting { constructor({ reference, party, date, description }) { diff --git a/fixtures/standardCOA.js b/fixtures/standardCOA.js index 18816987..f793474d 100644 --- a/fixtures/standardCOA.js +++ b/fixtures/standardCOA.js @@ -1,173 +1,173 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; const _ = frappe._.bind(frappe); export default { - [_("Application of Funds (Assets)")]: { - [_("Current Assets")]: { - [_("Accounts Receivable")]: { - [_("Debtors")]: { - "accountType": "Receivable" - } - }, - [_("Bank Accounts")]: { - "accountType": "Bank", - "isGroup": 1 - }, - [_("Cash In Hand")]: { - [_("Cash")]: { - "accountType": "Cash" - }, - "accountType": "Cash" - }, - [_("Loans and Advances (Assets)")]: { - "isGroup": 1 - }, - [_("Securities and Deposits")]: { - [_("Earnest Money")]: {} - }, - [_("Stock Assets")]: { - [_("Stock In Hand")]: { - "accountType": "Stock" - }, - "accountType": "Stock", - }, - [_("Tax Assets")]: { - "isGroup": 1 - } + [_('Application of Funds (Assets)')]: { + [_('Current Assets')]: { + [_('Accounts Receivable')]: { + [_('Debtors')]: { + accountType: 'Receivable', }, - [_("Fixed Assets")]: { - [_("Capital Equipments")]: { - "accountType": "Fixed Asset" - }, - [_("Electronic Equipments")]: { - "accountType": "Fixed Asset" - }, - [_("Furnitures and Fixtures")]: { - "accountType": "Fixed Asset" - }, - [_("Office Equipments")]: { - "accountType": "Fixed Asset" - }, - [_("Plants and Machineries")]: { - "accountType": "Fixed Asset" - }, - [_("Buildings")]: { - "accountType": "Fixed Asset" - }, - [_("Softwares")]: { - "accountType": "Fixed Asset" - }, - [_("Accumulated Depreciation")]: { - "accountType": "Accumulated Depreciation" - } + }, + [_('Bank Accounts')]: { + accountType: 'Bank', + isGroup: 1, + }, + [_('Cash In Hand')]: { + [_('Cash')]: { + accountType: 'Cash', }, - [_("Investments")]: { - "isGroup": 1 + accountType: 'Cash', + }, + [_('Loans and Advances (Assets)')]: { + isGroup: 1, + }, + [_('Securities and Deposits')]: { + [_('Earnest Money')]: {}, + }, + [_('Stock Assets')]: { + [_('Stock In Hand')]: { + accountType: 'Stock', }, - [_("Temporary Accounts")]: { - [_("Temporary Opening")]: { - "accountType": "Temporary" - } - }, - "rootType": "Asset" + accountType: 'Stock', + }, + [_('Tax Assets')]: { + isGroup: 1, + }, }, - [_("Expenses")]: { - [_("Direct Expenses")]: { - [_("Stock Expenses")]: { - [_("Cost of Goods Sold")]: { - "accountType": "Cost of Goods Sold" - }, - [_("Expenses Included In Valuation")]: { - "accountType": "Expenses Included In Valuation" - }, - [_("Stock Adjustment")]: { - "accountType": "Stock Adjustment" - } - }, - }, - [_("Indirect Expenses")]: { - [_("Administrative Expenses")]: {}, - [_("Commission on Sales")]: {}, - [_("Depreciation")]: { - "accountType": "Depreciation" - }, - [_("Entertainment Expenses")]: {}, - [_("Freight and Forwarding Charges")]: { - "accountType": "Chargeable" - }, - [_("Legal Expenses")]: {}, - [_("Marketing Expenses")]: { - "accountType": "Chargeable" - }, - [_("Miscellaneous Expenses")]: { - "accountType": "Chargeable" - }, - [_("Office Maintenance Expenses")]: {}, - [_("Office Rent")]: {}, - [_("Postal Expenses")]: {}, - [_("Print and Stationery")]: {}, - [_("Round Off")]: { - "accountType": "Round Off" - }, - [_("Salary")]: {}, - [_("Sales Expenses")]: {}, - [_("Telephone Expenses")]: {}, - [_("Travel Expenses")]: {}, - [_("Utility Expenses")]: {}, - [_("Write Off")]: {}, - [_("Exchange Gain/Loss")]: {}, - [_("Gain/Loss on Asset Disposal")]: {} - }, - "rootType": "Expense" + [_('Fixed Assets')]: { + [_('Capital Equipments')]: { + accountType: 'Fixed Asset', + }, + [_('Electronic Equipments')]: { + accountType: 'Fixed Asset', + }, + [_('Furnitures and Fixtures')]: { + accountType: 'Fixed Asset', + }, + [_('Office Equipments')]: { + accountType: 'Fixed Asset', + }, + [_('Plants and Machineries')]: { + accountType: 'Fixed Asset', + }, + [_('Buildings')]: { + accountType: 'Fixed Asset', + }, + [_('Softwares')]: { + accountType: 'Fixed Asset', + }, + [_('Accumulated Depreciation')]: { + accountType: 'Accumulated Depreciation', + }, }, - [_("Income")]: { - [_("Direct Income")]: { - [_("Sales")]: {}, - [_("Service")]: {} - }, - [_("Indirect Income")]: { - "isGroup": 1 - }, - "rootType": "Income" + [_('Investments')]: { + isGroup: 1, }, - [_("Source of Funds (Liabilities)")]: { - [_("Current Liabilities")]: { - [_("Accounts Payable")]: { - [_("Creditors")]: { - "accountType": "Payable" - }, - [_("Payroll Payable")]: {}, - }, - [_("Stock Liabilities")]: { - [_("Stock Received But Not Billed")]: { - "accountType": "Stock Received But Not Billed" - }, - }, - [_("Duties and Taxes")]: { - "accountType": "Tax", - "isGroup": 1 - }, - [_("Loans (Liabilities)")]: { - [_("Secured Loans")]: {}, - [_("Unsecured Loans")]: {}, - [_("Bank Overdraft Account")]: {}, - }, - }, - "rootType": "Liability" + [_('Temporary Accounts')]: { + [_('Temporary Opening')]: { + accountType: 'Temporary', + }, }, - [_("Equity")]: { - [_("Capital Stock")]: { - "accountType": "Equity" + rootType: 'Asset', + }, + [_('Expenses')]: { + [_('Direct Expenses')]: { + [_('Stock Expenses')]: { + [_('Cost of Goods Sold')]: { + accountType: 'Cost of Goods Sold', }, - [_("Dividends Paid")]: { - "accountType": "Equity" + [_('Expenses Included In Valuation')]: { + accountType: 'Expenses Included In Valuation', }, - [_("Opening Balance Equity")]: { - "accountType": "Equity" + [_('Stock Adjustment')]: { + accountType: 'Stock Adjustment', }, - [_("Retained Earnings")]: { - "accountType": "Equity" + }, + }, + [_('Indirect Expenses')]: { + [_('Administrative Expenses')]: {}, + [_('Commission on Sales')]: {}, + [_('Depreciation')]: { + accountType: 'Depreciation', + }, + [_('Entertainment Expenses')]: {}, + [_('Freight and Forwarding Charges')]: { + accountType: 'Chargeable', + }, + [_('Legal Expenses')]: {}, + [_('Marketing Expenses')]: { + accountType: 'Chargeable', + }, + [_('Miscellaneous Expenses')]: { + accountType: 'Chargeable', + }, + [_('Office Maintenance Expenses')]: {}, + [_('Office Rent')]: {}, + [_('Postal Expenses')]: {}, + [_('Print and Stationery')]: {}, + [_('Round Off')]: { + accountType: 'Round Off', + }, + [_('Salary')]: {}, + [_('Sales Expenses')]: {}, + [_('Telephone Expenses')]: {}, + [_('Travel Expenses')]: {}, + [_('Utility Expenses')]: {}, + [_('Write Off')]: {}, + [_('Exchange Gain/Loss')]: {}, + [_('Gain/Loss on Asset Disposal')]: {}, + }, + rootType: 'Expense', + }, + [_('Income')]: { + [_('Direct Income')]: { + [_('Sales')]: {}, + [_('Service')]: {}, + }, + [_('Indirect Income')]: { + isGroup: 1, + }, + rootType: 'Income', + }, + [_('Source of Funds (Liabilities)')]: { + [_('Current Liabilities')]: { + [_('Accounts Payable')]: { + [_('Creditors')]: { + accountType: 'Payable', }, - "rootType": "Equity" - } -}; \ No newline at end of file + [_('Payroll Payable')]: {}, + }, + [_('Stock Liabilities')]: { + [_('Stock Received But Not Billed')]: { + accountType: 'Stock Received But Not Billed', + }, + }, + [_('Duties and Taxes')]: { + accountType: 'Tax', + isGroup: 1, + }, + [_('Loans (Liabilities)')]: { + [_('Secured Loans')]: {}, + [_('Unsecured Loans')]: {}, + [_('Bank Overdraft Account')]: {}, + }, + }, + rootType: 'Liability', + }, + [_('Equity')]: { + [_('Capital Stock')]: { + accountType: 'Equity', + }, + [_('Dividends Paid')]: { + accountType: 'Equity', + }, + [_('Opening Balance Equity')]: { + accountType: 'Equity', + }, + [_('Retained Earnings')]: { + accountType: 'Equity', + }, + rootType: 'Equity', + }, +}; diff --git a/frappe/backends/database.js b/frappe/backends/database.js index cda95769..8f4d2434 100644 --- a/frappe/backends/database.js +++ b/frappe/backends/database.js @@ -1,6 +1,6 @@ -const frappe = require('frappejs'); -const Observable = require('frappejs/utils/observable'); -const CacheManager = require('frappejs/utils/cacheManager'); +const frappe = require('frappe'); +const Observable = require('frappe/utils/observable'); +const CacheManager = require('frappe/utils/cacheManager'); const Knex = require('knex'); module.exports = class Database extends Observable { diff --git a/frappe/backends/http.js b/frappe/backends/http.js index 8753fa38..57af0f0e 100644 --- a/frappe/backends/http.js +++ b/frappe/backends/http.js @@ -1,6 +1,6 @@ -const frappe = require('frappejs'); -const Observable = require('frappejs/utils/observable'); -const triggerEvent = name => frappe.events.trigger(`http:${name}`); +const frappe = require('frappe'); +const Observable = require('frappe/utils/observable'); +const triggerEvent = (name) => frappe.events.trigger(`http:${name}`); module.exports = class HTTPClient extends Observable { constructor({ server, protocol = 'http' }) { @@ -16,9 +16,7 @@ module.exports = class HTTPClient extends Observable { this.initTypeMap(); } - connect() { - - } + connect() {} async insert(doctype, doc) { doc.doctype = doctype; @@ -27,7 +25,7 @@ module.exports = class HTTPClient extends Observable { const responseDoc = await this.fetch(url, { method: 'POST', - body: JSON.stringify(doc) + body: JSON.stringify(doc), }); await this.uploadFilesAndUpdateDoc(filesToUpload, doctype, responseDoc); @@ -40,21 +38,24 @@ module.exports = class HTTPClient extends Observable { let url = this.getURL('/api/resource', doctype, name); return await this.fetch(url, { method: 'GET', - headers: this.getHeaders() - }) + headers: this.getHeaders(), + }); } async getAll({ doctype, fields, filters, start, limit, sortBy, order }) { let url = this.getURL('/api/resource', doctype); - url = url + '?' + frappe.getQueryString({ - fields: JSON.stringify(fields), - filters: JSON.stringify(filters), - start: start, - limit: limit, - sortBy: sortBy, - order: order - }); + url = + url + + '?' + + frappe.getQueryString({ + fields: JSON.stringify(fields), + filters: JSON.stringify(filters), + start: start, + limit: limit, + sortBy: sortBy, + order: order, + }); return await this.fetch(url, { method: 'GET', @@ -68,7 +69,7 @@ module.exports = class HTTPClient extends Observable { const responseDoc = await this.fetch(url, { method: 'PUT', - body: JSON.stringify(doc) + body: JSON.stringify(doc), }); await this.uploadFilesAndUpdateDoc(filesToUpload, doctype, responseDoc); @@ -89,7 +90,7 @@ module.exports = class HTTPClient extends Observable { return await this.fetch(url, { method: 'DELETE', - body: JSON.stringify(names) + body: JSON.stringify(names), }); } @@ -100,9 +101,11 @@ module.exports = class HTTPClient extends Observable { async getValue(doctype, name, fieldname) { let url = this.getURL('/api/resource', doctype, name, fieldname); - return (await this.fetch(url, { - method: 'GET', - })).value; + return ( + await this.fetch(url, { + method: 'GET', + }) + ).value; } async fetch(url, args) { @@ -131,13 +134,13 @@ module.exports = class HTTPClient extends Observable { const filesToUpload = []; if (fileFields.length > 0) { - fileFields.forEach(df => { + fileFields.forEach((df) => { const files = doc[df.fieldname] || []; if (files.length) { filesToUpload.push({ fieldname: df.fieldname, - files: files - }) + files: files, + }); } delete doc[df.fieldname]; }); @@ -150,7 +153,12 @@ module.exports = class HTTPClient extends Observable { if (filesToUpload.length > 0) { // upload files for (const fileToUpload of filesToUpload) { - const files = await this.uploadFiles(fileToUpload.files, doctype, doc.name, fileToUpload.fieldname); + const files = await this.uploadFiles( + fileToUpload.files, + doctype, + doc.name, + fileToUpload.fieldname + ); doc[fileToUpload.fieldname] = files[0].name; } } @@ -166,7 +174,7 @@ module.exports = class HTTPClient extends Observable { let response = await frappe.fetch(url, { method: 'POST', - body: formData + body: formData, }); const data = await response.json(); @@ -182,49 +190,46 @@ module.exports = class HTTPClient extends Observable { getHeaders() { const headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + Accept: 'application/json', + 'Content-Type': 'application/json', }; if (frappe.session && frappe.session.token) { headers.token = frappe.session.token; - }; + } return headers; } initTypeMap() { this.typeMap = { - 'AutoComplete': true - , 'Currency': true - , 'Int': true - , 'Float': true - , 'Percent': true - , 'Check': true - , 'Small Text': true - , 'Long Text': true - , 'Code': true - , 'Text Editor': true - , 'Date': true - , 'Datetime': true - , 'Time': true - , 'Text': true - , 'Data': true - , 'Link': true - , 'DynamicLink': true - , 'Password': true - , 'Select': true - , 'Read Only': true - , 'File': true - , 'Attach': true - , 'Attach Image': true - , 'Signature': true - , 'Color': true - , 'Barcode': true - , 'Geolocation': true - } + AutoComplete: true, + Currency: true, + Int: true, + Float: true, + Percent: true, + Check: true, + 'Small Text': true, + 'Long Text': true, + Code: true, + 'Text Editor': true, + Date: true, + Datetime: true, + Time: true, + Text: true, + Data: true, + Link: true, + DynamicLink: true, + Password: true, + Select: true, + 'Read Only': true, + File: true, + Attach: true, + 'Attach Image': true, + Signature: true, + Color: true, + Barcode: true, + Geolocation: true, + }; } - close() { - - } - -} + close() {} +}; diff --git a/frappe/backends/mysql.js b/frappe/backends/mysql.js index 891a6539..f544f3cf 100644 --- a/frappe/backends/mysql.js +++ b/frappe/backends/mysql.js @@ -1,210 +1,238 @@ -const frappe = require('frappejs'); +const frappe = require('frappe'); const mysql = require('mysql'); const Database = require('./database'); const debug = false; +module.exports = class mysqlDatabase extends Database { + constructor({ db_name, username, password, host }) { + super(); + this.db_name = db_name; + this.username = username; + this.password = password; + this.host = host; + this.init_typeMap(); + } -module.exports = class mysqlDatabase extends Database{ - constructor({ db_name, username, password, host }) { - super(); - this.db_name = db_name; - this.username = username; - this.password = password; - this.host = host; - this.init_typeMap(); + connect(db_name) { + if (db_name) { + this.db_name = db_name; } - - connect(db_name) { - if (db_name) { - this.db_name = db_name; + return new Promise((resolve) => { + this.conn = new mysql.createConnection({ + host: this.host, + user: this.username, + password: this.password, + database: this.db_name, + }); + () => { + if (debug) { + this.conn.on('trace', (trace) => console.log(trace)); } - return new Promise(resolve => { - this.conn = new mysql.createConnection({ - host : this.host, - user : this.username, - password : this.password, - database : this.db_name - }); - () => { - if (debug) { - this.conn.on('trace', (trace) => console.log(trace)); - } - }; - resolve(); - }); + }; + resolve(); + }); + } - } - - async tableExists(table) { - - const name = await this.sql(`SELECT table_name + async tableExists(table) { + const name = await this.sql(`SELECT table_name FROM information_schema.tables WHERE table_schema = '${this.db_name}' AND table_name = '${table}'`); - return (name && name.length) ? true : false; - } + return name && name.length ? true : false; + } - async runCreateTableQuery(doctype, columns, values){ - const query = `CREATE TABLE IF NOT EXISTS ${doctype} ( - ${columns.join(", ")})`; + async runCreateTableQuery(doctype, columns, values) { + const query = `CREATE TABLE IF NOT EXISTS ${doctype} ( + ${columns.join(', ')})`; - return await this.run(query, values); - } + return await this.run(query, values); + } + updateColumnDefinition(df, columns, indexes) { + columns.push( + `${df.fieldname} ${this.typeMap[df.fieldtype]} ${ + df.required && !df.default ? 'not null' : '' + } ${df.default ? `default '${df.default}'` : ''}` + ); + } - updateColumnDefinition(df, columns, indexes) { - columns.push(`${df.fieldname} ${this.typeMap[df.fieldtype]} ${df.required && !df.default ? "not null" : ""} ${df.default ? `default '${df.default}'` : ""}`); - } + async getTableColumns(doctype) { + return (await this.sql(`SHOW COLUMNS FROM ${doctype}`)).map((d) => d.Field); + } - async getTableColumns(doctype) { - return (await this.sql(`SHOW COLUMNS FROM ${doctype}`)).map(d => d.Field); - } + async runAddColumnQuery(doctype, fields) { + await this.run( + `ALTER TABLE ${doctype} ADD COLUMN ${this.get_column_definition(doctype)}` + ); + } + getOne(doctype, name, fields = '*') { + fields = this.prepareFields(fields); - async runAddColumnQuery(doctype, fields) { - await this.run(`ALTER TABLE ${doctype} ADD COLUMN ${this.get_column_definition(doctype)}`); - } - - getOne(doctype, name, fields = '*') { - - fields = this.prepareFields(fields); - - return new Promise((resolve, reject) => { - this.conn.get(`select ${fields} from ${doctype} - where name = ?`, name, - (err, row) => { - resolve(row || {}); - }); - }); - } - - async insertOne(doctype, doc) { - let fields = this.get_keys(doctype); - let placeholders = fields.map(d => '?').join(', '); - - if (!doc.name) { - doc.name = frappe.getRandomString(); + return new Promise((resolve, reject) => { + this.conn.get( + `select ${fields} from ${doctype} + where name = ?`, + name, + (err, row) => { + resolve(row || {}); } + ); + }); + } - return await this.run(`insert into ${doctype} - (${fields.map(field => field.fieldname).join(", ")}) - values (${placeholders})`, this.getFormattedValues(fields, doc)); + async insertOne(doctype, doc) { + let fields = this.get_keys(doctype); + let placeholders = fields.map((d) => '?').join(', '); + + if (!doc.name) { + doc.name = frappe.getRandomString(); } - async updateOne(doctype, doc) { - let fields = this.getKeys(doctype); - let assigns = fields.map(field => `${field.fieldname} = ?`); - let values = this.getFormattedValues(fields, doc); + return await this.run( + `insert into ${doctype} + (${fields.map((field) => field.fieldname).join(', ')}) + values (${placeholders})`, + this.getFormattedValues(fields, doc) + ); + } - // additional name for where clause - values.push(doc.name); + async updateOne(doctype, doc) { + let fields = this.getKeys(doctype); + let assigns = fields.map((field) => `${field.fieldname} = ?`); + let values = this.getFormattedValues(fields, doc); - return await this.run(`update ${doctype} - set ${assigns.join(", ")} where name=?`, values); - } + // additional name for where clause + values.push(doc.name); - async runDeleteOtherChildren(field, added) { - await this.run(`delete from ${field.childtype} + return await this.run( + `update ${doctype} + set ${assigns.join(', ')} where name=?`, + values + ); + } + + async runDeleteOtherChildren(field, added) { + await this.run( + `delete from ${field.childtype} where parent = ? and - name not in (${added.slice(1).map(d => '?').join(', ')})`, added); + name not in (${added + .slice(1) + .map((d) => '?') + .join(', ')})`, + added + ); + } + + async deleteOne(doctype, name) { + return await this.run(`delete from ${doctype} where name=?`, name); + } + + async deleteChildren(parenttype, parent) { + await this.run(`delete from ${parent} where parent=?`, parent); + } + + getAll({ + doctype, + fields, + filters, + start, + limit, + order_by = 'modified', + order = 'desc', + } = {}) { + if (!fields) { + fields = frappe.getMeta(doctype).getKeywordFields(); } + return new Promise((resolve, reject) => { + let conditions = this.getFilterConditions(filters); - async deleteOne(doctype, name) { - return await this.run(`delete from ${doctype} where name=?`, name); - } - - async deleteChildren(parenttype, parent) { - await this.run(`delete from ${parent} where parent=?`, parent); - } - - - getAll({ doctype, fields, filters, start, limit, order_by = 'modified', order = 'desc' } = {}) { - if (!fields) { - fields = frappe.getMeta(doctype).getKeywordFields(); - } - return new Promise((resolve, reject) => { - let conditions = this.getFilterConditions(filters); - - this.conn.all(`select ${fields.join(", ")} + this.conn.all( + `select ${fields.join(', ')} from ${doctype} - ${conditions.conditions ? "where" : ""} ${conditions.conditions} - ${order_by ? ("order by " + order_by) : ""} ${order_by ? (order || "asc") : ""} - ${limit ? ("limit " + limit) : ""} ${start ? ("offset " + start) : ""}`, conditions.values, - (err, rows) => { - if (err) { - reject(err); - } else { - resolve(rows); - } - }); - }); - } - - run(query, params) { - // TODO promisify - return new Promise((resolve, reject) => { - this.conn.query(query, params, (err) => { - if (err) { - if (debug) { - console.error(err); - } - reject(err); - } else { - resolve(); - } - }); - }); - } - - sql(query, params) { - return new Promise((resolve) => { - this.conn.query(query, params, (err, rows) => { - resolve(rows); - }); - }); - } - - async commit() { - try { - await this.run('commit'); - } catch (e) { - if (e.errno !== 1) { - throw e; - } + ${conditions.conditions ? 'where' : ''} ${conditions.conditions} + ${order_by ? 'order by ' + order_by : ''} ${ + order_by ? order || 'asc' : '' } - } - - - init_typeMap() { - this.typeMap = { - 'AutoComplete': 'VARCHAR(140)' - , 'Currency': 'real' - , 'Int': 'INT' - , 'Float': 'decimal(18,6)' - , 'Percent': 'real' - , 'Check': 'INT(1)' - , 'Small Text': 'text' - , 'Long Text': 'text' - , 'Code': 'text' - , 'Text Editor': 'text' - , 'Date': 'DATE' - , 'Datetime': 'DATETIME' - , 'Time': 'TIME' - , 'Text': 'text' - , 'Data': 'VARCHAR(140)' - , 'Link': ' varchar(140)' - , 'DynamicLink': 'text' - , 'Password': 'varchar(140)' - , 'Select': 'VARCHAR(140)' - , 'Read Only': 'varchar(140)' - , 'File': 'text' - , 'Attach': 'text' - , 'Attach Image': 'text' - , 'Signature': 'text' - , 'Color': 'text' - , 'Barcode': 'text' - , 'Geolocation': 'text' + ${limit ? 'limit ' + limit : ''} ${ + start ? 'offset ' + start : '' + }`, + conditions.values, + (err, rows) => { + if (err) { + reject(err); + } else { + resolve(rows); + } } + ); + }); + } + + run(query, params) { + // TODO promisify + return new Promise((resolve, reject) => { + this.conn.query(query, params, (err) => { + if (err) { + if (debug) { + console.error(err); + } + reject(err); + } else { + resolve(); + } + }); + }); + } + + sql(query, params) { + return new Promise((resolve) => { + this.conn.query(query, params, (err, rows) => { + resolve(rows); + }); + }); + } + + async commit() { + try { + await this.run('commit'); + } catch (e) { + if (e.errno !== 1) { + throw e; + } } -} + } + + init_typeMap() { + this.typeMap = { + AutoComplete: 'VARCHAR(140)', + Currency: 'real', + Int: 'INT', + Float: 'decimal(18,6)', + Percent: 'real', + Check: 'INT(1)', + 'Small Text': 'text', + 'Long Text': 'text', + Code: 'text', + 'Text Editor': 'text', + Date: 'DATE', + Datetime: 'DATETIME', + Time: 'TIME', + Text: 'text', + Data: 'VARCHAR(140)', + Link: ' varchar(140)', + DynamicLink: 'text', + Password: 'varchar(140)', + Select: 'VARCHAR(140)', + 'Read Only': 'varchar(140)', + File: 'text', + Attach: 'text', + 'Attach Image': 'text', + Signature: 'text', + Color: 'text', + Barcode: 'text', + Geolocation: 'text', + }; + } +}; diff --git a/frappe/backends/sqlite.js b/frappe/backends/sqlite.js index 7d7911ed..d198e83a 100644 --- a/frappe/backends/sqlite.js +++ b/frappe/backends/sqlite.js @@ -1,4 +1,4 @@ -const frappe = require('frappejs'); +const frappe = require('frappe'); const Database = require('./database'); class SqliteDatabase extends Database { diff --git a/frappe/common/errors.js b/frappe/common/errors.js index 9771c444..3d1f4da2 100644 --- a/frappe/common/errors.js +++ b/frappe/common/errors.js @@ -1,4 +1,4 @@ -const frappe = require('frappejs'); +const frappe = require('frappe'); class BaseError extends Error { constructor(statusCode, message) { @@ -75,7 +75,7 @@ function throwError(message, error = 'ValidationError') { NotFoundError: NotFoundError, ForbiddenError: ForbiddenError, ValueError: ValueError, - Conflict: Conflict + Conflict: Conflict, }; const err = new errorClass[error](message); frappe.events.trigger('throw', { message, stackTrace: err.stack }); @@ -97,5 +97,5 @@ module.exports = { CannotCommitError, MandatoryError, InvalidFieldError, - throw: throwError + throw: throwError, }; diff --git a/frappe/common/index.js b/frappe/common/index.js index 50e71fba..a32701ec 100644 --- a/frappe/common/index.js +++ b/frappe/common/index.js @@ -1,8 +1,8 @@ const utils = require('../utils'); const format = require('../utils/format'); const errors = require('./errors'); -const BaseDocument = require('frappejs/model/document'); -const BaseMeta = require('frappejs/model/meta'); +const BaseDocument = require('frappe/model/document'); +const BaseMeta = require('frappe/model/meta'); module.exports = { initLibs(frappe) { diff --git a/frappe/index.js b/frappe/index.js index efcf938e..363a2c55 100644 --- a/frappe/index.js +++ b/frappe/index.js @@ -9,9 +9,9 @@ const { module.exports = { initializeAndRegister(customModels = {}, force = false) { this.init(force); - const common = require('frappejs/common'); + const common = require('frappe/common'); this.registerLibs(common); - const coreModels = require('frappejs/models'); + const coreModels = require('frappe/models'); this.registerModels(coreModels); this.registerModels(customModels); }, diff --git a/frappe/model/document.js b/frappe/model/document.js index fbaa8eeb..bdf2f7e9 100644 --- a/frappe/model/document.js +++ b/frappe/model/document.js @@ -1,5 +1,5 @@ -const frappe = require('frappejs'); -const Observable = require('frappejs/utils/observable'); +const frappe = require('frappe'); +const Observable = require('frappe/utils/observable'); const naming = require('./naming'); const { isPesa } = require('../utils/index'); const { DEFAULT_INTERNAL_PRECISION } = require('../utils/consts'); diff --git a/frappe/model/meta.js b/frappe/model/meta.js index 2c43da80..e720d73f 100644 --- a/frappe/model/meta.js +++ b/frappe/model/meta.js @@ -1,7 +1,7 @@ const BaseDocument = require('./document'); -const frappe = require('frappejs'); +const frappe = require('frappe'); const model = require('./index'); -const indicatorColor = require('frappejs/ui/constants/indicators'); +const indicatorColor = require('frappe/ui/constants/indicators'); module.exports = class BaseMeta extends BaseDocument { constructor(data) { diff --git a/frappe/model/naming.js b/frappe/model/naming.js index 85753b9d..9a515271 100644 --- a/frappe/model/naming.js +++ b/frappe/model/naming.js @@ -1,88 +1,92 @@ -const frappe = require('frappejs'); -const { getRandomString } = require('frappejs/utils'); +const frappe = require('frappe'); +const { getRandomString } = require('frappe/utils'); module.exports = { - async setName(doc) { - if (frappe.isServer) { - // if is server, always name again if autoincrement or other - if (doc.meta.naming === 'autoincrement') { - doc.name = await this.getNextId(doc.doctype); - return; - } + async setName(doc) { + if (frappe.isServer) { + // if is server, always name again if autoincrement or other + if (doc.meta.naming === 'autoincrement') { + doc.name = await this.getNextId(doc.doctype); + return; + } - if (doc.meta.settings) { - const numberSeries = (await doc.getSettings()).numberSeries; - if(numberSeries) { - doc.name = await this.getSeriesNext(numberSeries); - } - } - } - - if (doc.name) { - return; - } - - // name === doctype for Single - if (doc.meta.isSingle) { - doc.name = doc.meta.name; - return; - } - - // assign a random name by default - // override doc to set a name - if (!doc.name) { - doc.name = getRandomString(); - } - }, - - async getNextId(doctype) { - // get the last inserted row - let lastInserted = await this.getLastInserted(doctype); - let name = 1; - if (lastInserted) { - let lastNumber = parseInt(lastInserted.name); - if (isNaN(lastNumber)) lastNumber = 0; - name = lastNumber + 1; - } - return (name + '').padStart(9, '0'); - }, - - async getLastInserted(doctype) { - const lastInserted = await frappe.db.getAll({ - doctype: doctype, - fields: ['name'], - limit: 1, - order_by: 'creation', - order: 'desc' - }); - return (lastInserted && lastInserted.length) ? lastInserted[0] : null; - }, - - async getSeriesNext(prefix) { - let series; - try { - series = await frappe.getDoc('NumberSeries', prefix); - } catch (e) { - if (!e.statusCode || e.statusCode !== 404) { - throw e; - } - await this.createNumberSeries(prefix); - series = await frappe.getDoc('NumberSeries', prefix); - } - let next = await series.next() - return prefix + next; - }, - - async createNumberSeries(prefix, setting, start=1000) { - if (!(await frappe.db.exists('NumberSeries', prefix))) { - const series = frappe.newDoc({doctype: 'NumberSeries', name: prefix, current: start}); - await series.insert(); - - if (setting) { - const settingDoc = await frappe.getSingle(setting); - settingDoc.numberSeries = series.name; - await settingDoc.update(); - } + if (doc.meta.settings) { + const numberSeries = (await doc.getSettings()).numberSeries; + if (numberSeries) { + doc.name = await this.getSeriesNext(numberSeries); } + } } -} + + if (doc.name) { + return; + } + + // name === doctype for Single + if (doc.meta.isSingle) { + doc.name = doc.meta.name; + return; + } + + // assign a random name by default + // override doc to set a name + if (!doc.name) { + doc.name = getRandomString(); + } + }, + + async getNextId(doctype) { + // get the last inserted row + let lastInserted = await this.getLastInserted(doctype); + let name = 1; + if (lastInserted) { + let lastNumber = parseInt(lastInserted.name); + if (isNaN(lastNumber)) lastNumber = 0; + name = lastNumber + 1; + } + return (name + '').padStart(9, '0'); + }, + + async getLastInserted(doctype) { + const lastInserted = await frappe.db.getAll({ + doctype: doctype, + fields: ['name'], + limit: 1, + order_by: 'creation', + order: 'desc', + }); + return lastInserted && lastInserted.length ? lastInserted[0] : null; + }, + + async getSeriesNext(prefix) { + let series; + try { + series = await frappe.getDoc('NumberSeries', prefix); + } catch (e) { + if (!e.statusCode || e.statusCode !== 404) { + throw e; + } + await this.createNumberSeries(prefix); + series = await frappe.getDoc('NumberSeries', prefix); + } + let next = await series.next(); + return prefix + next; + }, + + async createNumberSeries(prefix, setting, start = 1000) { + if (!(await frappe.db.exists('NumberSeries', prefix))) { + const series = frappe.newDoc({ + doctype: 'NumberSeries', + name: prefix, + current: start, + }); + await series.insert(); + + if (setting) { + const settingDoc = await frappe.getSingle(setting); + settingDoc.numberSeries = series.name; + await settingDoc.update(); + } + } + }, +}; diff --git a/frappe/model/runPatches.js b/frappe/model/runPatches.js index 3da2d29d..0901003e 100644 --- a/frappe/model/runPatches.js +++ b/frappe/model/runPatches.js @@ -1,4 +1,4 @@ -const frappe = require('frappejs'); +const frappe = require('frappe'); module.exports = async function runPatches(patchList) { const patchesAlreadyRun = ( diff --git a/frappe/models/doctype/NumberSeries/NumberSeriesDocument.js b/frappe/models/doctype/NumberSeries/NumberSeriesDocument.js index 704e3edc..ade8f2c8 100644 --- a/frappe/models/doctype/NumberSeries/NumberSeriesDocument.js +++ b/frappe/models/doctype/NumberSeries/NumberSeriesDocument.js @@ -1,15 +1,15 @@ -const BaseDocument = require('frappejs/model/document'); +const BaseDocument = require('frappe/model/document'); module.exports = class NumberSeries extends BaseDocument { - validate() { - if (this.current===null || this.current===undefined) { - this.current = 0; - } + validate() { + if (this.current === null || this.current === undefined) { + this.current = 0; } - async next() { - this.validate(); - this.current++; - await this.update(); - return this.current; - } -} \ No newline at end of file + } + async next() { + this.validate(); + this.current++; + await this.update(); + return this.current; + } +}; diff --git a/frappe/models/doctype/SystemSettings/SystemSettings.js b/frappe/models/doctype/SystemSettings/SystemSettings.js index b77bfb04..fc011f4f 100644 --- a/frappe/models/doctype/SystemSettings/SystemSettings.js +++ b/frappe/models/doctype/SystemSettings/SystemSettings.js @@ -1,5 +1,5 @@ const { DateTime } = require('luxon'); -const { _ } = require('frappejs/utils'); +const { _ } = require('frappe/utils'); const { DEFAULT_DISPLAY_PRECISION, DEFAULT_INTERNAL_PRECISION, diff --git a/frappe/models/doctype/ToDo/ToDo.js b/frappe/models/doctype/ToDo/ToDo.js index 3dad8d04..82bb055b 100644 --- a/frappe/models/doctype/ToDo/ToDo.js +++ b/frappe/models/doctype/ToDo/ToDo.js @@ -1,4 +1,4 @@ -const { BLUE, GREEN } = require('frappejs/ui/constants/indicators'); +const { BLUE, GREEN } = require('frappe/ui/constants/indicators'); module.exports = { name: 'ToDo', @@ -11,8 +11,8 @@ module.exports = { key: 'status', colors: { Open: BLUE, - Closed: GREEN - } + Closed: GREEN, + }, }, fields: [ { @@ -20,7 +20,7 @@ module.exports = { label: 'Subject', placeholder: 'Subject', fieldtype: 'Data', - required: 1 + required: 1, }, { fieldname: 'status', @@ -28,13 +28,13 @@ module.exports = { fieldtype: 'Select', options: ['Open', 'Closed'], default: 'Open', - required: 1 + required: 1, }, { fieldname: 'description', label: 'Description', - fieldtype: 'Text' - } + fieldtype: 'Text', + }, ], quickEditFields: ['status', 'description'], @@ -42,19 +42,19 @@ module.exports = { actions: [ { label: 'Close', - condition: doc => doc.status !== 'Closed', - action: async doc => { + condition: (doc) => doc.status !== 'Closed', + action: async (doc) => { await doc.set('status', 'Closed'); await doc.update(); - } + }, }, { label: 'Re-Open', - condition: doc => doc.status !== 'Open', - action: async doc => { + condition: (doc) => doc.status !== 'Open', + action: async (doc) => { await doc.set('status', 'Open'); await doc.update(); - } - } - ] + }, + }, + ], }; diff --git a/frappe/models/doctype/ToDo/ToDoList.js b/frappe/models/doctype/ToDo/ToDoList.js index 9611ab78..893d6475 100644 --- a/frappe/models/doctype/ToDo/ToDoList.js +++ b/frappe/models/doctype/ToDo/ToDoList.js @@ -1,7 +1,7 @@ -const BaseList = require('frappejs/client/view/list'); +const BaseList = require('frappe/client/view/list'); module.exports = class ToDoList extends BaseList { - getFields(list) { - return ['name', 'subject', 'status']; - } -} + getFields(list) { + return ['name', 'subject', 'status']; + } +}; diff --git a/frappe/utils/format.js b/frappe/utils/format.js index 731d5c64..dc915bfe 100644 --- a/frappe/utils/format.js +++ b/frappe/utils/format.js @@ -1,5 +1,5 @@ const luxon = require('luxon'); -const frappe = require('frappejs'); +const frappe = require('frappe'); const { DEFAULT_DISPLAY_PRECISION, DEFAULT_LOCALE } = require('./consts'); module.exports = { diff --git a/models/doctype/Account/Account.js b/models/doctype/Account/Account.js index f859f8d3..9b0093db 100644 --- a/models/doctype/Account/Account.js +++ b/models/doctype/Account/Account.js @@ -1,4 +1,4 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; import Account from './AccountDocument'; export default { diff --git a/models/doctype/Account/AccountDocument.js b/models/doctype/Account/AccountDocument.js index 54fcd8ae..b16f1463 100644 --- a/models/doctype/Account/AccountDocument.js +++ b/models/doctype/Account/AccountDocument.js @@ -1,5 +1,5 @@ -import frappe from 'frappejs'; -import BaseDocument from 'frappejs/model/document'; +import frappe from 'frappe'; +import BaseDocument from 'frappe/model/document'; export default class Account extends BaseDocument { async validate() { @@ -11,4 +11,4 @@ export default class Account extends BaseDocument { ); } } -}; +} diff --git a/models/doctype/Account/AccountList.js b/models/doctype/Account/AccountList.js index 46d2fdd2..b4fc80d6 100644 --- a/models/doctype/Account/AccountList.js +++ b/models/doctype/Account/AccountList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappejs/utils'; +import { _ } from 'frappe/utils'; export default { doctype: 'Account', title: _('Account'), - columns: ['name', 'parentAccount', 'rootType'] + columns: ['name', 'parentAccount', 'rootType'], }; diff --git a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js index f67d05e3..5903eb52 100644 --- a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js +++ b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js @@ -1,13 +1,7 @@ -import { _ } from 'frappejs/utils'; +import { _ } from 'frappe/utils'; export default { doctype: 'AccountingLedgerEntry', title: _('Accounting Ledger Entries'), - columns: [ - 'account', - 'party', - 'debit', - 'credit', - 'balance' - ] -} + columns: ['account', 'party', 'debit', 'credit', 'balance'], +}; diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 59cb2612..e640e4c5 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -1,72 +1,73 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; export default { - "name": "Email", - "doctype": "DocType", - "pageSettings": { - hideTitle: true + name: 'Email', + doctype: 'DocType', + pageSettings: { + hideTitle: true, + }, + isSingle: 0, + isChild: 0, + keywordFields: ['name'], + fields: [ + { + fieldname: 'name', + label: 'name', + fieldtype: 'Data', + required: 0, + hidden: 1, + disabled: 0, }, - "isSingle": 0, - "isChild": 0, - "keywordFields": ["name"], - "fields": [{ - "fieldname": "name", - "label": "name", - "fieldtype": "Data", - "required": 0, - "hidden": 1, - "disabled": 0 - }, - { - "fieldname": "fromEmailAddress", - "label": "From", - "fieldtype": "Data", - "required": 1, - "hidden": 0, - formula: async () => { - const accountingSettings = await frappe.getDoc('AccountingSettings'); - return accountingSettings.email; - }, - "disabled": 1 - }, - { - "fieldname": "toEmailAddress", - "label": "To", - "fieldtype": "Data", - "required": 1, - "hidden": 0, - "disabled": 0 - }, - { - "fieldname": "date", - "label": "Date", - "fieldtype": "Datetime", - "required": 0, - "hidden": 0, - "disabled": 1 - }, - { - "fieldname": "subject", - "label": "Subject", - "fieldtype": "Data", - "required": 0, - "hidden": 0, - "disabled": 0 - }, - { - "fieldname": "bodyText", - "label": "Body", - "fieldtype": "Text", - "required": 0, - "hidden": 0, - "disabled": 0 - }, - { - "fieldname": "filePath", - "label": "File Path", - "fieldtype": "Text", - "required": 0, - "hidden": 1, - } - ] -}; \ No newline at end of file + { + fieldname: 'fromEmailAddress', + label: 'From', + fieldtype: 'Data', + required: 1, + hidden: 0, + formula: async () => { + const accountingSettings = await frappe.getDoc('AccountingSettings'); + return accountingSettings.email; + }, + disabled: 1, + }, + { + fieldname: 'toEmailAddress', + label: 'To', + fieldtype: 'Data', + required: 1, + hidden: 0, + disabled: 0, + }, + { + fieldname: 'date', + label: 'Date', + fieldtype: 'Datetime', + required: 0, + hidden: 0, + disabled: 1, + }, + { + fieldname: 'subject', + label: 'Subject', + fieldtype: 'Data', + required: 0, + hidden: 0, + disabled: 0, + }, + { + fieldname: 'bodyText', + label: 'Body', + fieldtype: 'Text', + required: 0, + hidden: 0, + disabled: 0, + }, + { + fieldname: 'filePath', + label: 'File Path', + fieldtype: 'Text', + required: 0, + hidden: 1, + }, + ], +}; diff --git a/models/doctype/EmailAccount/EmailAccount.js b/models/doctype/EmailAccount/EmailAccount.js index 77b9fc74..fadfe4a2 100644 --- a/models/doctype/EmailAccount/EmailAccount.js +++ b/models/doctype/EmailAccount/EmailAccount.js @@ -1,59 +1,54 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; export default { - "name": "EmailAccount", - "label": "Email Account", - "doctype": "DocType", - "isSingle": true, - "isChild": false, - "keywordFields": [ - "email" - ], - "fields": [ - { - "fieldname": "email", - "label": "Email", - "fieldtype": "Data", - "required": 1, - formula: async () => { - const accountingSettings = await frappe.getDoc('AccountingSettings'); - return accountingSettings.email; - }, - }, - { - "fieldname": "password", - "label": "Password", - "fieldtype": "Password", - "required": 1 - }, - { - "fieldname": "confirmPassword", - "label": "Confirm Password", - "fieldtype": "Password", - "required": 1 - }, - { - "fieldname": "smtpHost", - "label": "SMTP Host", - "fieldtype": "Select", - "options": [ - "smtp.gmail.com", - "smtp.mail.yahoo.com", - "smtp-mail.outlook.com", - "smtp.mail.me.com", - "smtp.aol.com" - ], - "default": "smtp.gmail.com" - }, - { - "fieldname": "smtpPort", - "label": "SMTP Port", - "fieldtype": "Select", - "options": [ - "465", - "587" - ], - "default": "465" - } - ] -}; \ No newline at end of file + name: 'EmailAccount', + label: 'Email Account', + doctype: 'DocType', + isSingle: true, + isChild: false, + keywordFields: ['email'], + fields: [ + { + fieldname: 'email', + label: 'Email', + fieldtype: 'Data', + required: 1, + formula: async () => { + const accountingSettings = await frappe.getDoc('AccountingSettings'); + return accountingSettings.email; + }, + }, + { + fieldname: 'password', + label: 'Password', + fieldtype: 'Password', + required: 1, + }, + { + fieldname: 'confirmPassword', + label: 'Confirm Password', + fieldtype: 'Password', + required: 1, + }, + { + fieldname: 'smtpHost', + label: 'SMTP Host', + fieldtype: 'Select', + options: [ + 'smtp.gmail.com', + 'smtp.mail.yahoo.com', + 'smtp-mail.outlook.com', + 'smtp.mail.me.com', + 'smtp.aol.com', + ], + default: 'smtp.gmail.com', + }, + { + fieldname: 'smtpPort', + label: 'SMTP Port', + fieldtype: 'Select', + options: ['465', '587'], + default: '465', + }, + ], +}; diff --git a/models/doctype/Event/EventDocument.js b/models/doctype/Event/EventDocument.js index 5a943173..077fbad4 100644 --- a/models/doctype/Event/EventDocument.js +++ b/models/doctype/Event/EventDocument.js @@ -1,8 +1,7 @@ -import frappe from 'frappejs'; -import BaseDocument from 'frappejs/model/document'; +import BaseDocument from 'frappe/model/document'; export default class Event extends BaseDocument { - alertEvent() { - alert(this.title); - } -}; + alertEvent() { + alert(this.title); + } +} diff --git a/models/doctype/Fulfillment/Fulfillment.js b/models/doctype/Fulfillment/Fulfillment.js index 8164fb79..e1a9c836 100644 --- a/models/doctype/Fulfillment/Fulfillment.js +++ b/models/doctype/Fulfillment/Fulfillment.js @@ -1,14 +1,14 @@ -import model from 'frappejs/model'; +import model from 'frappe/model'; import Quotation from '../Quotation/Quotation'; export default model.extend(Quotation, { - name: "Fulfillment", - label: "Fulfillment", - settings: "FulfillmentSettings", - fields: [ - { - "fieldname": "items", - "childtype": "FulfillmentItem" - } - ] + name: 'Fulfillment', + label: 'Fulfillment', + settings: 'FulfillmentSettings', + fields: [ + { + fieldname: 'items', + childtype: 'FulfillmentItem', + }, + ], }); diff --git a/models/doctype/FulfillmentItem/FulfillmentItem.js b/models/doctype/FulfillmentItem/FulfillmentItem.js index a4ab16aa..331e19ed 100644 --- a/models/doctype/FulfillmentItem/FulfillmentItem.js +++ b/models/doctype/FulfillmentItem/FulfillmentItem.js @@ -1,6 +1,6 @@ -import model from 'frappejs/model'; +import model from 'frappe/model'; import QuotationItem from '../QuotationItem/QuotationItem'; export default model.extend(QuotationItem, { - name: "FulfillmentItem" + name: 'FulfillmentItem', }); diff --git a/models/doctype/FulfillmentSettings/FulfillmentSettings.js b/models/doctype/FulfillmentSettings/FulfillmentSettings.js index 9b0c0015..45e07560 100644 --- a/models/doctype/FulfillmentSettings/FulfillmentSettings.js +++ b/models/doctype/FulfillmentSettings/FulfillmentSettings.js @@ -1,13 +1,13 @@ -import model from 'frappejs/model'; +import model from 'frappe/model'; import QuotationSettings from '../QuotationSettings/QuotationSettings'; export default model.extend(QuotationSettings, { - "name": "FulfillmentSettings", - "label": "Fulfillment Settings", - "fields": [ - { - "fieldname": "numberSeries", - "default": "OF" - } - ] + name: 'FulfillmentSettings', + label: 'Fulfillment Settings', + fields: [ + { + fieldname: 'numberSeries', + default: 'OF', + }, + ], }); diff --git a/models/doctype/GSTR3B/GSTR3B.js b/models/doctype/GSTR3B/GSTR3B.js index a9c1abb2..93b25885 100644 --- a/models/doctype/GSTR3B/GSTR3B.js +++ b/models/doctype/GSTR3B/GSTR3B.js @@ -1,4 +1,4 @@ -import frappe from 'frappejs'; +import frappe from 'frappe'; import GSTR3B from './GSTR3BDocument.js'; export default { diff --git a/models/doctype/GSTR3B/GSTR3BDocument.js b/models/doctype/GSTR3B/GSTR3BDocument.js index e5394224..31721db5 100644 --- a/models/doctype/GSTR3B/GSTR3BDocument.js +++ b/models/doctype/GSTR3B/GSTR3BDocument.js @@ -1,5 +1,5 @@ -import BaseDocument from 'frappejs/model/document'; -import frappe from 'frappejs'; +import frappe from 'frappe'; +import BaseDocument from 'frappe/model/document'; import format from './GSTR3BFormat'; export default class GSTR3B extends BaseDocument { @@ -16,7 +16,7 @@ export default class GSTR3B extends BaseDocument { 'September', 'October', 'November', - 'December' + 'December', ].indexOf(this.month); const month = monthIndex + 1 > 9 ? monthIndex + 1 : `0${monthIndex + 1}`; const lastDate = new Date(this.year, monthIndex + 1, 0).getDate(); @@ -25,22 +25,22 @@ export default class GSTR3B extends BaseDocument { '>=', `${this.year}-${month}-01`, '<=', - `${this.year}-${month}-${lastDate}` - ] + `${this.year}-${month}-${lastDate}`, + ], }; const salesInvoices = frappe.db.getAll({ doctype: 'SalesInvoice', filters, - fields: ['*'] + fields: ['*'], }); const purchaseInvoices = frappe.db.getAll({ doctype: 'PurchaseInvoice', filters, - fields: ['*'] + fields: ['*'], }); const [gstr1Data, gstr2Data] = await Promise.all([ salesInvoices, - purchaseInvoices + purchaseInvoices, ]); let gstr3bData = [[], []]; @@ -74,7 +74,7 @@ export default class GSTR3B extends BaseDocument { row.rate = 0; row.inState = true; row.reverseCharge = !party.gstin ? 'Y' : 'N'; - ledgerEntry.taxes.forEach(tax => { + ledgerEntry.taxes.forEach((tax) => { row.rate += tax.rate; const taxAmt = (tax.rate * ledgerEntry.netTotal) / 100; if (tax.account === 'IGST') row.igstAmt = taxAmt; @@ -113,7 +113,7 @@ export default class GSTR3B extends BaseDocument { jsonData['inter_sup']['unreg_details'].push({ pos: ledgerEntry.place, txval: ledgerEntry.taxVal, - iAmt: ledgerEntry.igstAmt || 0 + iAmt: ledgerEntry.igstAmt || 0, }); } } @@ -147,4 +147,4 @@ export default class GSTR3B extends BaseDocument { return JSON.stringify(json, undefined, 2); } } -}; +} diff --git a/models/doctype/GSTR3B/GSTR3BList.js b/models/doctype/GSTR3B/GSTR3BList.js index 480f1f25..f9ca5810 100644 --- a/models/doctype/GSTR3B/GSTR3BList.js +++ b/models/doctype/GSTR3B/GSTR3BList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappejs/utils'; +import { _ } from 'frappe/utils'; export default { doctype: 'GSTR3B', title: _('GSTR 3B Report'), - columns: ['year', 'month'] + columns: ['year', 'month'], }; diff --git a/models/doctype/Item/Item.js b/models/doctype/Item/Item.js index 3a096093..abeb4145 100644 --- a/models/doctype/Item/Item.js +++ b/models/doctype/Item/Item.js @@ -1,5 +1,5 @@ -import frappe from 'frappejs'; -import { _ } from 'frappejs/utils'; +import frappe from 'frappe'; +import { _ } from 'frappe/utils'; export default { name: 'Item', diff --git a/models/doctype/Item/ItemList.js b/models/doctype/Item/ItemList.js index 25ea2ca6..b48bde6f 100644 --- a/models/doctype/Item/ItemList.js +++ b/models/doctype/Item/ItemList.js @@ -1,12 +1,7 @@ -import { _ } from 'frappejs/utils'; +import { _ } from 'frappe/utils'; export default { doctype: 'Item', title: _('Items'), - columns: [ - 'name', - 'unit', - 'tax', - 'rate', - ] -} + columns: ['name', 'unit', 'tax', 'rate'], +}; diff --git a/models/doctype/JournalEntry/JournalEntryList.js b/models/doctype/JournalEntry/JournalEntryList.js index b9481a38..abe57328 100644 --- a/models/doctype/JournalEntry/JournalEntryList.js +++ b/models/doctype/JournalEntry/JournalEntryList.js @@ -1,10 +1,10 @@ -import { _ } from 'frappejs/utils'; import Badge from '@/components/Badge'; +import { _ } from 'frappe/utils'; export default { doctype: 'JournalEntry', title: _('Journal Entry'), - formRoute: name => `/edit/JournalEntry/${name}`, + formRoute: (name) => `/edit/JournalEntry/${name}`, columns: [ 'date', { @@ -35,10 +35,10 @@ export default { fieldname: 'name', fieldtype: 'Data', getValue(doc) { - return doc.name - } + return doc.name; + }, }, 'entryType', - 'referenceNumber' - ] + 'referenceNumber', + ], }; diff --git a/models/doctype/JournalEntry/JournalEntryServer.js b/models/doctype/JournalEntry/JournalEntryServer.js index f9a271ed..c081e720 100644 --- a/models/doctype/JournalEntry/JournalEntryServer.js +++ b/models/doctype/JournalEntry/JournalEntryServer.js @@ -1,4 +1,4 @@ -import BaseDocument from 'frappejs/model/document'; +import BaseDocument from 'frappe/model/document'; import LedgerPosting from '../../../accounting/ledgerPosting'; export default class JournalEntryServer extends BaseDocument { diff --git a/models/doctype/Party/Customer.js b/models/doctype/Party/Customer.js index 86c01c88..897b84ef 100644 --- a/models/doctype/Party/Customer.js +++ b/models/doctype/Party/Customer.js @@ -1,6 +1,6 @@ -import frappe from 'frappejs'; -import { _ } from 'frappejs/utils'; import router from '@/router'; +import frappe from 'frappe'; +import { _ } from 'frappe/utils'; import PartyWidget from './PartyWidget.vue'; export default { @@ -8,46 +8,46 @@ export default { label: 'Customer', basedOn: 'Party', filters: { - customer: 1 + customer: 1, }, actions: [ { label: _('Create Invoice'), - condition: doc => !doc.isNew(), - action: async customer => { + condition: (doc) => !doc.isNew(), + action: async (customer) => { let doc = await frappe.getNewDoc('SalesInvoice'); router.push({ path: `/edit/SalesInvoice/${doc.name}`, query: { doctype: 'SalesInvoice', values: { - customer: customer.name - } - } + customer: customer.name, + }, + }, }); - } + }, }, { label: _('View Invoices'), - condition: doc => !doc.isNew(), - action: customer => { + condition: (doc) => !doc.isNew(), + action: (customer) => { router.push({ name: 'ListView', params: { doctype: 'SalesInvoice', filters: { - customer: customer.name - } - } + customer: customer.name, + }, + }, }); - } - } + }, + }, ], - quickEditWidget: doc => ({ + quickEditWidget: (doc) => ({ render(h) { return h(PartyWidget, { - props: { doc } + props: { doc }, }); - } - }) + }, + }), }; diff --git a/models/doctype/Party/CustomerList.js b/models/doctype/Party/CustomerList.js index 39b13d36..0118f9b3 100644 --- a/models/doctype/Party/CustomerList.js +++ b/models/doctype/Party/CustomerList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappejs/utils'; +import { _ } from 'frappe/utils'; export default { doctype: 'Customer', title: _('Customers'), - columns: ['name', 'phone', 'outstandingAmount'] + columns: ['name', 'phone', 'outstandingAmount'], }; diff --git a/models/doctype/Party/Party.js b/models/doctype/Party/Party.js index f7c2c663..a7931866 100644 --- a/models/doctype/Party/Party.js +++ b/models/doctype/Party/Party.js @@ -1,5 +1,5 @@ -import frappe from 'frappejs'; -import { _ } from 'frappejs/utils'; +import frappe from 'frappe'; +import { _ } from 'frappe/utils'; export default { name: 'Party', diff --git a/models/doctype/Party/PartyList.js b/models/doctype/Party/PartyList.js index a6f48f6c..ee158c71 100644 --- a/models/doctype/Party/PartyList.js +++ b/models/doctype/Party/PartyList.js @@ -1,6 +1,4 @@ -import { _ } from 'frappejs/utils'; - export default { doctype: 'Party', - columns: ['name', 'phone', 'outstandingAmount'] + columns: ['name', 'phone', 'outstandingAmount'], }; diff --git a/models/doctype/Party/PartyServer.js b/models/doctype/Party/PartyServer.js index bd53c5f4..e572a630 100644 --- a/models/doctype/Party/PartyServer.js +++ b/models/doctype/Party/PartyServer.js @@ -1,5 +1,5 @@ -import frappe from 'frappejs'; -import BaseDocument from 'frappejs/model/document'; +import frappe from 'frappe'; +import BaseDocument from 'frappe/model/document'; export default class PartyServer extends BaseDocument { beforeInsert() { diff --git a/models/doctype/Party/PartyWidget.vue b/models/doctype/Party/PartyWidget.vue index 8ed0ff2a..dd06058e 100644 --- a/models/doctype/Party/PartyWidget.vue +++ b/models/doctype/Party/PartyWidget.vue @@ -50,7 +50,7 @@