From 2afec6a74baf3725c528a30081d1c01d158b3da4 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 22 Mar 2022 13:51:00 +0530 Subject: [PATCH] incr: deprecate frappe.call --- models/doctype/GSTR3B/GSTR3BServer.js | 9 +-- models/doctype/Party/PartyServer.js | 9 +-- .../BankReconciliationImport.js | 8 +- reports/index.js | 81 +++++-------------- server/postStart.js | 3 - server/registerServerMethods.js | 5 -- src/pages/Report.vue | 6 +- 7 files changed, 25 insertions(+), 96 deletions(-) delete mode 100644 server/registerServerMethods.js diff --git a/models/doctype/GSTR3B/GSTR3BServer.js b/models/doctype/GSTR3B/GSTR3BServer.js index 424f480d..fe7c006f 100644 --- a/models/doctype/GSTR3B/GSTR3BServer.js +++ b/models/doctype/GSTR3B/GSTR3BServer.js @@ -3,14 +3,7 @@ import GSTR3B from './GSTR3BDocument'; export default class GSTR3BServer extends GSTR3B { async validate() { if (this.month.length === 0 || this.year.length != 4) { - frappe.call({ - method: 'show-dialog', - args: { - title: 'Invalid Entry', - message: `Month or Year is not valid` - } - }); - throw new Error(); + throw new Error('Month or Year is not valid'); } } async beforeInsert() { diff --git a/models/doctype/Party/PartyServer.js b/models/doctype/Party/PartyServer.js index 6145ad88..56868140 100644 --- a/models/doctype/Party/PartyServer.js +++ b/models/doctype/Party/PartyServer.js @@ -4,14 +4,7 @@ import Document from 'frappe/model/document'; export default class PartyServer extends Document { beforeInsert() { if (this.customer && this.supplier) { - frappe.call({ - method: 'show-dialog', - args: { - title: 'Invalid Entry', - message: 'Select a single party type.', - }, - }); - throw new Error(); + throw new Error('Select a single party type.'); } if (!this.customer && !this.supplier) { diff --git a/reports/BankReconciliation/BankReconciliationImport.js b/reports/BankReconciliation/BankReconciliationImport.js index a9745d88..f6534ff6 100644 --- a/reports/BankReconciliation/BankReconciliationImport.js +++ b/reports/BankReconciliation/BankReconciliationImport.js @@ -84,12 +84,6 @@ export const findMatchingReferences = async (json, report) => { }, }); } else { - frappe.call({ - method: 'show-dialog', - args: { - title: 'Message', - message: 'No entries found with matching Ref / Cheque ID', - }, - }); + // 'No entries found with matching Ref / Cheque ID' } }; diff --git a/reports/index.js b/reports/index.js index 3a0a255f..22b16db7 100644 --- a/reports/index.js +++ b/reports/index.js @@ -1,4 +1,3 @@ -import frappe from 'frappe'; import AccountsReceivablePayable from './AccountsReceivablePayable/AccountsReceivablePayable'; import BalanceSheet from './BalanceSheet/BalanceSheet'; import BankReconciliation from './BankReconciliation/BankReconciliation'; @@ -10,67 +9,27 @@ import PurchaseRegister from './PurchaseRegister/PurchaseRegister'; import SalesRegister from './SalesRegister/SalesRegister'; import TrialBalance from './TrialBalance/TrialBalance'; -// called on server side -function registerReportMethods() { - const reports = [ - { - method: 'general-ledger', - class: GeneralLedger, - }, - { - method: 'profit-and-loss', - class: ProfitAndLoss, - }, - { - method: 'balance-sheet', - class: BalanceSheet, - }, - { - method: 'trial-balance', - class: TrialBalance, - }, - { - method: 'sales-register', - class: SalesRegister, - }, - { - method: 'purchase-register', - class: PurchaseRegister, - }, - { - method: 'bank-reconciliation', - class: BankReconciliation, - }, - { - method: 'gstr-1', - class: GSTR1, - }, - { - method: 'gstr-2', - class: GSTR2, - }, - ]; +export function getReportData(method, filters) { + const reports = { + 'general-ledger': GeneralLedger, + 'profit-and-loss': ProfitAndLoss, + 'balance-sheet': BalanceSheet, + 'trial-balance': TrialBalance, + 'gstr-1': GSTR1, + 'gstr-2': GSTR2, + 'sales-register': SalesRegister, + 'purchase-register': PurchaseRegister, + 'bank-reconciliation': BankReconciliation, + }; - reports.forEach((report) => { - frappe.registerMethod({ - method: report.method, - handler: getReportData(report.class), - }); - }); + if (method === 'accounts-receivable') { + return new AccountsReceivablePayable().run('Receivable', filters); + } - frappe.registerMethod({ - method: 'accounts-receivable', - handler: (args) => new AccountsReceivablePayable().run('Receivable', args), - }); + if (method === 'accounts-payable') { + return new AccountsReceivablePayable().run('Payable', filters); + } - frappe.registerMethod({ - method: 'accounts-payable', - handler: (args) => new AccountsReceivablePayable().run('Payable', args), - }); + const ReportClass = reports[method]; + return new ReportClass().run(filters); } - -function getReportData(ReportClass) { - return (args) => new ReportClass().run(args); -} - -export default registerReportMethods; diff --git a/server/postStart.js b/server/postStart.js index a7ea0bbe..c574e911 100644 --- a/server/postStart.js +++ b/server/postStart.js @@ -6,7 +6,6 @@ import PartyServer from '../models/doctype/Party/PartyServer.js'; import PaymentServer from '../models/doctype/Payment/PaymentServer.js'; import PurchaseInvoiceServer from '../models/doctype/PurchaseInvoice/PurchaseInvoiceServer.js'; import SalesInvoiceServer from '../models/doctype/SalesInvoice/SalesInvoiceServer.js'; -import registerServerMethods from './registerServerMethods'; export default async function postStart() { // set server-side modules @@ -38,8 +37,6 @@ export default async function postStart() { // cache currency symbols for frappe.format await setCurrencySymbols(); - - registerServerMethods(); } export async function setCurrencySymbols() { diff --git a/server/registerServerMethods.js b/server/registerServerMethods.js deleted file mode 100644 index 200a73b2..00000000 --- a/server/registerServerMethods.js +++ /dev/null @@ -1,5 +0,0 @@ -import registerReportMethods from '../reports'; - -export default function registerServerMethods() { - registerReportMethods(); -} diff --git a/src/pages/Report.vue b/src/pages/Report.vue index 6a59ecde..5a556650 100644 --- a/src/pages/Report.vue +++ b/src/pages/Report.vue @@ -146,6 +146,7 @@ import SearchBar from '@/components/SearchBar'; import WithScroll from '@/components/WithScroll'; import frappe from 'frappe'; import { h, markRaw } from 'vue'; +import { getReportData } from '../../reports/index'; import DropdownWithActions from '../components/DropdownWithActions.vue'; export default { @@ -195,10 +196,7 @@ export default { }); }, async fetchReportData() { - let data = await frappe.call({ - method: this.report.method, - args: this.filters, - }); + let data = await getReportData(this.report.method, this.filters) let rows; if (data.rows) {