Skip to content

Commit

Permalink
feat: GSTR-1 Download all Json
Browse files Browse the repository at this point in the history
Co-authored-by: Smit Vora <[email protected]>
(cherry picked from commit 1aa2c20)
  • Loading branch information
vishakhdesai authored and mergify[bot] committed Oct 25, 2023
1 parent 65fcbe8 commit d698be0
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 120 deletions.
29 changes: 1 addition & 28 deletions india_compliance/gst_india/client_scripts/e_waybill_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function show_generate_e_waybill_dialog(frm) {
);

frm.refresh();
trigger_file_download(ewb_data, get_e_waybill_file_name(frm.doc.name));
india_compliance.trigger_file_download(ewb_data, get_e_waybill_file_name(frm.doc.name));
};

const api_enabled = india_compliance.is_api_enabled();
Expand Down Expand Up @@ -1098,33 +1098,6 @@ function get_transit_type(dialog) {
* Utils
*******/

function trigger_file_download(file_content, file_name) {
let type = "application/json;charset=utf-8";

if (!file_name.endsWith(".json")) {
type = "application/octet-stream";
}

const blob = new Blob([file_content], { type: type });

// Create a link and set the URL using `createObjectURL`
const link = document.createElement("a");
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.download = file_name;

// It needs to be added to the DOM so it can be clicked
document.body.appendChild(link);
link.click();

// To make this work on Firefox we need to wait
// a little while before removing it.
setTimeout(() => {
URL.revokeObjectURL(link.href);
link.parentNode.removeChild(link);
}, 0);
}

function get_e_waybill_file_name(docname) {
let prefix = "Bulk";
if (docname) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function generate_e_waybill_json(docnames) {
{ doctype: DOCTYPE, docnames }
);

trigger_file_download(ewb_data, get_e_waybill_file_name());
india_compliance.trigger_file_download(ewb_data, get_e_waybill_file_name());
}

function show_bulk_update_transporter_dialog(docnames) {
Expand Down
102 changes: 67 additions & 35 deletions india_compliance/gst_india/report/gstr_1/gstr_1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
const TYPES_OF_BUSINESS = {
"B2B": __("B2B Invoices - 4A, 4B, 4C, 6B, 6C"),
"B2C Large": __("B2C(Large) Invoices - 5A, 5B"),
"B2C Small": __("B2C(Small) Invoices - 7"),
"CDNR-REG": __("Credit/Debit Notes (Registered) - 9B"),
"CDNR-UNREG": __("Credit/Debit Notes (Unregistered) - 9B"),
"EXPORT": __("Export Invoice - 6A"),
"Advances": __("Tax Liability (Advances Received) - 11A(1), 11A(2)"),
"Adjustment": __("Adjustment of Advances - 11B(1), 11B(2)"),
"NIL Rated": __("NIL RATED/EXEMPTED Invoices")
};


frappe.query_reports["GSTR-1"] = {
"filters": [
Expand Down Expand Up @@ -55,41 +67,61 @@ frappe.query_reports["GSTR-1"] = {
"label": __("Type of Business"),
"fieldtype": "Select",
"reqd": 1,
"options": [
{ "value": "B2B", "label": __("B2B Invoices - 4A, 4B, 4C, 6B, 6C") },
{ "value": "B2C Large", "label": __("B2C(Large) Invoices - 5A, 5B") },
{ "value": "B2C Small", "label": __("B2C(Small) Invoices - 7") },
{ "value": "CDNR-REG", "label": __("Credit/Debit Notes (Registered) - 9B") },
{ "value": "CDNR-UNREG", "label": __("Credit/Debit Notes (Unregistered) - 9B") },
{ "value": "EXPORT", "label": __("Export Invoice - 6A") },
{ "value": "Advances", "label": __("Tax Liability (Advances Received) - 11A(1), 11A(2)") },
{ "value": "Adjustment", "label": __("Adjustment of Advances - 11B(1), 11B(2)") },
{ "value": "NIL Rated", "label": __("NIL RATED/EXEMPTED Invoices") }
],
"default": "B2B"
"options": Object.entries(TYPES_OF_BUSINESS).map(([value, label]) => ({
value,
label
})),
"default": "B2B",
"on_change": (report) => {
report.page.get_inner_group_button("Download as JSON")
.find(".dropdown-item").remove();
create_download_buttons(report);
report.refresh();
},
}
],
onload: function (report) {
report.page.add_inner_button(__("Download as JSON"), function () {
frappe.call({
method: 'india_compliance.gst_india.report.gstr_1.gstr_1.get_json',
args: {
data: report.data,
report_name: report.report_name,
filters: report.get_values()
},
callback: function(r) {
if (r.message) {
const args = {
cmd: 'india_compliance.gst_india.report.gstr_1.gstr_1.download_json_file',
data: r.message.data,
report_name: r.message.report_name,
report_type: r.message.report_type
};
open_url_post(frappe.request.url, args);
}
}
});
});
}
onload: create_download_buttons,
}

function create_download_buttons(report) {
report.page.add_inner_button(
TYPES_OF_BUSINESS[report.get_values().type_of_business],
() => download_current_report(report),
__("Download as JSON")
);

report.page.add_inner_button(
__("Full Report"),
() => download_full_report(report),
__("Download as JSON")
);
}

function download_current_report(report) {
frappe.call({
method: 'india_compliance.gst_india.report.gstr_1.gstr_1.get_gstr1_json',
args: {
data: report.data,
filters: report.get_values()
},
callback: function (r) {
if (r.message) {
india_compliance.trigger_file_download(JSON.stringify(r.message.data), r.message.file_name);
}
}
});
}

function download_full_report(report) {
frappe.call({
method: 'india_compliance.gst_india.report.gstr_1.gstr_1.get_gstr1_json',
args: {
filters: report.get_values(),
},
callback: function (r) {
if (r.message) {
india_compliance.trigger_file_download(JSON.stringify(r.message.data), r.message.file_name);
}
}
});
}
Loading

0 comments on commit d698be0

Please sign in to comment.