mirror of
https://github.com/frappe/books.git
synced 2025-01-11 02:36:14 +00:00
frappe.call
This commit is contained in:
parent
1e43969daf
commit
b9840722a2
@ -10,7 +10,7 @@ module.exports = class GeneralLedgerView extends ReportPage {
|
|||||||
this.addFilter({fieldtype: 'Date', label: 'From Date'});
|
this.addFilter({fieldtype: 'Date', label: 'From Date'});
|
||||||
this.addFilter({fieldtype: 'Date', label: 'To Date'});
|
this.addFilter({fieldtype: 'Date', label: 'To Date'});
|
||||||
|
|
||||||
this.url = '/api/report/general-ledger';
|
this.method = 'general-ledger';
|
||||||
}
|
}
|
||||||
|
|
||||||
getColumns() {
|
getColumns() {
|
||||||
|
@ -17,10 +17,13 @@ module.exports = {
|
|||||||
|
|
||||||
frappe.syncDoc(require('../fixtures/invoicePrint'));
|
frappe.syncDoc(require('../fixtures/invoicePrint'));
|
||||||
|
|
||||||
frappe.app.get('/api/report/general-ledger', frappe.asyncHandler(async function(request, response) {
|
frappe.registerMethod({
|
||||||
|
method: 'general-ledger',
|
||||||
|
type: 'get',
|
||||||
|
handler: async (args) => {
|
||||||
const generalLedger = new GeneralLedger();
|
const generalLedger = new GeneralLedger();
|
||||||
const data = await generalLedger.run(request.query);
|
return await generalLedger.run(args);
|
||||||
response.json(data);
|
}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
www/dist/js/bundle.js
vendored
73
www/dist/js/bundle.js
vendored
@ -51,10 +51,13 @@ var utils = {
|
|||||||
|
|
||||||
getQueryString(params) {
|
getQueryString(params) {
|
||||||
if (!params) return '';
|
if (!params) return '';
|
||||||
return Object.keys(params)
|
let parts = [];
|
||||||
.map(k => params[k] != null ? encodeURIComponent(k) + '=' + encodeURIComponent(params[k]) : null)
|
for (let key in params) {
|
||||||
.filter(v => v)
|
if (key!=null && params[key]!=null) {
|
||||||
.join('&');
|
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts.join('&');
|
||||||
},
|
},
|
||||||
|
|
||||||
asyncHandler(fn) {
|
asyncHandler(fn) {
|
||||||
@ -9130,6 +9133,7 @@ var frappejs = {
|
|||||||
this.forms = {};
|
this.forms = {};
|
||||||
this.views = {};
|
this.views = {};
|
||||||
this.flags = {};
|
this.flags = {};
|
||||||
|
this.methods = {};
|
||||||
// temp params while calling routes
|
// temp params while calling routes
|
||||||
this.params = {};
|
this.params = {};
|
||||||
},
|
},
|
||||||
@ -9156,6 +9160,32 @@ var frappejs = {
|
|||||||
this.views[view][name] = module;
|
this.views[view][name] = module;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
registerMethod({method, type, handler}) {
|
||||||
|
type = type.toLowerCase();
|
||||||
|
this.methods[method] = handler;
|
||||||
|
if (this.app) {
|
||||||
|
// add to router if client-server
|
||||||
|
this.app[type](`/api/method/${method}`, this.asyncHandler(async function(request, response) {
|
||||||
|
let args = {};
|
||||||
|
if (type==='get') {
|
||||||
|
args = request.query;
|
||||||
|
} else {
|
||||||
|
args = request.body;
|
||||||
|
}
|
||||||
|
const data = await handler(args);
|
||||||
|
response.json(data);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
call({method, type, args}) {
|
||||||
|
if (this.methods[method]) {
|
||||||
|
return this.methods[method](args);
|
||||||
|
} else {
|
||||||
|
throw `${method} not found`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
addToCache(doc) {
|
addToCache(doc) {
|
||||||
if (!this.docs) return;
|
if (!this.docs) return;
|
||||||
|
|
||||||
@ -57521,6 +57551,8 @@ var client = {
|
|||||||
frappejs.registerModels(models, 'client');
|
frappejs.registerModels(models, 'client');
|
||||||
|
|
||||||
frappejs.fetch = window.fetch.bind();
|
frappejs.fetch = window.fetch.bind();
|
||||||
|
|
||||||
|
this.setCall();
|
||||||
frappejs.db = await new http({server: server});
|
frappejs.db = await new http({server: server});
|
||||||
this.socket = io.connect('http://localhost:8000'); // eslint-disable-line
|
this.socket = io.connect('http://localhost:8000'); // eslint-disable-line
|
||||||
frappejs.db.bindSocketClient(this.socket);
|
frappejs.db.bindSocketClient(this.socket);
|
||||||
@ -57531,6 +57563,29 @@ var client = {
|
|||||||
|
|
||||||
frappejs.desk = new desk(columns);
|
frappejs.desk = new desk(columns);
|
||||||
await frappejs.login();
|
await frappejs.login();
|
||||||
|
},
|
||||||
|
|
||||||
|
setCall() {
|
||||||
|
frappejs.call = async ({method, type='get', args}) => {
|
||||||
|
let url = `/api/method/${method}`;
|
||||||
|
let request = {};
|
||||||
|
|
||||||
|
if (args) {
|
||||||
|
if (type.toLowerCase()==='get') {
|
||||||
|
url += '?' + frappejs.getQueryString(args);
|
||||||
|
} else {
|
||||||
|
// POST / PUT / DELETE
|
||||||
|
request.body = JSON.stringify(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request.headers = { 'Accept': 'application/json' };
|
||||||
|
request.method = type.toUpperCase();
|
||||||
|
|
||||||
|
let response = await fetch(url, request);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57592,13 +57647,7 @@ var reportpage = class ReportPage extends page {
|
|||||||
const filterValues = this.getFilterValues();
|
const filterValues = this.getFilterValues();
|
||||||
if (filterValues === false) return;
|
if (filterValues === false) return;
|
||||||
|
|
||||||
let response = await fetch(this.url + '?' + frappejs.getQueryString(filterValues), {
|
let data = await frappejs.call({method: this.method, args: filterValues});
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const data = await response.json();
|
|
||||||
this.datatable.refresh(data);
|
this.datatable.refresh(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57620,7 +57669,7 @@ var GeneralLedgerView_1 = class GeneralLedgerView extends reportpage {
|
|||||||
this.addFilter({fieldtype: 'Date', label: 'From Date'});
|
this.addFilter({fieldtype: 'Date', label: 'From Date'});
|
||||||
this.addFilter({fieldtype: 'Date', label: 'To Date'});
|
this.addFilter({fieldtype: 'Date', label: 'To Date'});
|
||||||
|
|
||||||
this.url = '/api/report/general-ledger';
|
this.method = 'general-ledger';
|
||||||
}
|
}
|
||||||
|
|
||||||
getColumns() {
|
getColumns() {
|
||||||
|
Loading…
Reference in New Issue
Block a user