diff --git a/accounting/gst.js b/accounting/gst.js index 1186a709..11650dab 100644 --- a/accounting/gst.js +++ b/accounting/gst.js @@ -1,10 +1,9 @@ -import frappe from 'frappejs'; -import { _ } from 'frappejs/utils'; import { IPC_ACTIONS } from '@/messages'; -import { ipcRenderer } from 'electron'; -import { DateTime } from 'luxon'; -import { sleep } from 'frappejs/utils'; import { makeJSON, showMessageDialog } from '@/utils'; +import { ipcRenderer } from 'electron'; +import frappe from 'frappejs'; +import { sleep, _ } from 'frappejs/utils'; +import { DateTime } from 'luxon'; /** * GST is a map which gives a final rate for any given gst item @@ -59,14 +58,20 @@ const IGST = { 'IGST-28': 28, }; -export async function generateGstr1Json(report, { transferType, toDate }) { - const { gstin } = frappe.AccountingSettings - +export async function generateGstr1Json(getReportData) { + const { gstin } = frappe.AccountingSettings; if (!gstin) { - promptWhenGstUnavailable(); + showMessageDialog({ + message: _('Export Failed'), + description: _('Please set GSTIN in General Settings.'), + }); return; } + const { + rows, + filters: { transferType, toDate }, + } = getReportData(); const savePath = await getSavePath('gstr-1'); if (!savePath) return; @@ -82,11 +87,11 @@ export async function generateGstr1Json(report, { transferType, toDate }) { // based condition we need to triggered different methods if (transferType === 'B2B') { - gstData.b2b = await generateB2bData(report.rows); + gstData.b2b = await generateB2bData(rows); } else if (transferType === 'B2CL') { - gstData.b2cl = await generateB2clData(report.rows); + gstData.b2cl = await generateB2clData(rows); } else if (transferType === 'B2CS') { - gstData.b2cs = await generateB2csData(report.rows); + gstData.b2cs = await generateB2csData(rows); } await sleep(1); @@ -176,22 +181,3 @@ async function getSavePath(name) { return filePath; } - -export function promptWhenGstUnavailable() { - return new Promise((resolve) => { - showMessageDialog({ - message: _('Export failed'), - description: _( - 'Report cannot be exported if company gst details are not configured.' - ), - buttons: [ - { - label: _('Ok'), - action() { - resolve(true); - }, - }, - ], - }); - }); -} diff --git a/src/pages/Report.vue b/src/pages/Report.vue index 895d934c..21f87f54 100644 --- a/src/pages/Report.vue +++ b/src/pages/Report.vue @@ -279,11 +279,23 @@ export default { this.loading ? 'text-gray-100' : 'text-gray-900', ]; }, + getReportData() { + return { rows: this.rows, columns: this.columns, filters: this.filters }; + }, + getCurriedAction(action) { + return (...args) => action(this.getReportData, ...args); + }, }, computed: { actions() { return [ - ...(this.report.actions?.filter((action) => !action.group)??[]), + ...(this.report.actions + ?.filter((action) => !action.group) + .map((action) => + Object.assign({}, action, { + action: this.getCurriedAction(action.action), + }) + ) ?? []), { label: this._('Reset Filters'), action: this.resetFilters, @@ -297,6 +309,7 @@ export default { .reduce((acc, action) => { acc[action.group] ??= { type: action.type, actions: [] }; const actionWithoutGroup = Object.assign({}, action); + actionWithoutGroup.action = this.getCurriedAction(action.action); delete actionWithoutGroup.group; acc[action.group].actions.push(actionWithoutGroup); return acc;