Skip to content

Commit

Permalink
refactor: 3b report js to avoid duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit committed Jan 22, 2025
1 parent 232b7b2 commit 81e0ff9
Showing 1 changed file with 53 additions and 54 deletions.
107 changes: 53 additions & 54 deletions india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,62 @@
// For license information, please see license.txt

frappe.ui.form.on("GSTR 3B Report", {
refresh: function (frm) {
frm.doc.__unsaved = 1;
if (!frm.is_new()) {
frm.set_intro(__("Please save the report again to rebuild or update"));
frm.add_custom_button(__("Download JSON"), function () {
var w = window.open(
frappe.urllib.get_full_url(
"/api/method/india_compliance.gst_india.doctype.gstr_3b_report.gstr_3b_report.make_json?" +
"name=" +
encodeURIComponent(frm.doc.name)
)
);

if (!w) {
frappe.msgprint(__("Please enable pop-ups"));
return;
}
});
frm.add_custom_button(__("View Form"), function () {
frappe.call({
method: "india_compliance.gst_india.doctype.gstr_3b_report.gstr_3b_report.view_report",
args: {
name: frm.doc.name,
},
callback: function (r) {
let data = r.message;

frappe.ui.get_print_settings(false, print_settings => {
frappe.render_grid({
template: "gstr_3b_report",
title: __(this.doctype),
print_settings: print_settings,
data: data,
columns: [],
});
});
},
});
});
}

onload: function (frm) {
set_options_for_year_gstr3b(frm);

if (frm.doc.company)
india_compliance.set_gstin_options(frm).then(options => {
frm.set_value("company_gstin", options[0]);
});

frappe.realtime.on("gstr3b_report_generation", function () {
frm.reload_doc();
});

append_form(frm);
},

setup: async function (frm) {
await frappe.require(
"assets/india_compliance/js/components/set_gstin_options.js"
);
refresh: function (frm) {
if (frm.is_new()) return;

if (!frm.doc.company) return;
const options = await india_compliance.set_gstin_options(frm);
frm.set_value("company_gstin", options[0]);
frm.set_intro(__("Please save the report again to rebuild or update"));

set_options_for_year_gstr3b(frm);
frm.add_custom_button(__("Download JSON"), function () {
var w = window.open(
frappe.urllib.get_full_url(
"/api/method/india_compliance.gst_india.doctype.gstr_3b_report.gstr_3b_report.make_json?" +
"name=" +
encodeURIComponent(frm.doc.name)
)
);

if (!w) {
frappe.msgprint(__("Please enable pop-ups"));
return;
}
});

frm.add_custom_button(__("View Form"), function () {
frappe.call({
method: "india_compliance.gst_india.doctype.gstr_3b_report.gstr_3b_report.view_report",
args: {
name: frm.doc.name,
},
callback: function (r) {
let data = r.message;

frappe.ui.get_print_settings(false, print_settings => {
frappe.render_grid({
template: "gstr_3b_report",
title: __(this.doctype),
print_settings: print_settings,
data: data,
columns: [],
});
});
},
});
});

append_form(frm);
},

company: async function (frm) {
Expand All @@ -86,9 +82,12 @@ function append_form(frm) {
).appendTo(frm.fields_dict.gstr3b_form.wrapper);
}

function set_options_for_year_gstr3b(frm){
function set_options_for_year_gstr3b(frm) {
let current_year = new Date().getFullYear();
let options = [current_year, current_year - 1, current_year - 2];

frm.set_df_property("year", "options", options);
frm.set_value("year", frm.is_new() ? options[0] : frm.doc.year);
}

if (!frm.is_new()) return;
frm.set_value("year", options[0]);
}

0 comments on commit 81e0ff9

Please sign in to comment.