Skip to content

Commit

Permalink
Merge pull request #2960 from vorasmit/fix-gstr-1-round
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit authored Jan 14, 2025
2 parents 00ec2ca + ac77cce commit 4920eff
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,13 @@ def normalize_data(data):


class FileGSTR1:
def reset_gstr1(self, force):

def reset_gstr1(self, is_nil_return, force):
verify_request_in_progress(self, force)

# reset called after proceed to file
self.db_set({"filing_status": "Not Filed"})
self.db_set({"is_nil": sbool(is_nil_return)})

api = GSTR1API(self)
response = api.reset_gstr_1_data(self.return_period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _update_gstr_1_filed_upto(filing_date):
gstin_doc.gstr_1_filed_upto
):
gstin_doc.gstr_1_filed_upto = filing_date
gstin_doc.save()
gstin_doc.save(ignore_permissions=True)

# create or update filed logs
for key, info in return_info.items():
Expand Down
35 changes: 21 additions & 14 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ frappe.ui.form.on(DOCTYPE, {
const data = frm.doc.__gst_data;
if (!data?.status) return;

frm.doc.file_nil_gstr1 = data.is_nil
frm.doc.file_nil_gstr1 = data.is_nil;

// Toggle HTML fields
frm.refresh();
Expand Down Expand Up @@ -486,26 +486,32 @@ class GSTR1 {

// Primary Button
const actions = {
Reset: this.gstr1_action.reset_gstr1_data,
Generate: this.gstr1_action.generate_gstr1_data,
Upload: this.gstr1_action.upload_gstr1_data,
"Proceed to File": this.gstr1_action.proceed_to_file,
File: this.gstr1_action.file_gstr1_data,
};

// No need to upload if nil gstr1
const status =
this.frm.doc.file_nil_gstr1 && this.status == "Not Filed"
? "Uploaded"
: this.status;

let primary_button_label =
{
"Not Filed": "Upload",
Uploaded: "Proceed to File",
"Ready to File": "File",
}[status] || "Generate";
}[this.status] || "Generate";

// No need to upload if nil gstr1
if (this.frm.doc.__gst_data) {
if (this.frm.doc.file_nil_gstr1 != this.frm.doc.__gst_data.is_nil)
primary_button_label = "Reset";

if (this.status == "Not Filed")
if (this.frm.doc.file_nil_gstr1) primary_button_label = "Proceed to File";
else primary_button_label = "Upload";

}

if (status === "Ready to File") {
if (this.status === "Ready to File") {
this.frm.add_custom_button(__("Mark as Unfiled"), () => {
this.gstr1_action.mark_as_unfiled();
});
Expand Down Expand Up @@ -2151,8 +2157,7 @@ class FiledTab extends GSTR1_TabManager {
if (this.instance.data?.is_nil)
if (this.status === "Filed")
return __("You have filed a Nil GSTR-1 for this period");
else
return __("You are filing a Nil GSTR-1 for this period");
else return __("You are filing a Nil GSTR-1 for this period");

return this.DEFAULT_NO_DATA_MESSAGE;
}
Expand Down Expand Up @@ -2556,7 +2561,7 @@ class FileGSTR1Dialog {
this.perform_gstr1_action(
"file",
r => this.handle_filing_response(r.message),
{ pan: pan, otp: this.filing_dialog.get_value("otp") }
{ pan: pan, otp: this.filing_dialog.get_value("otp").trim() }
);

this.toggle_actions(true);
Expand Down Expand Up @@ -2674,8 +2679,10 @@ class GSTR1Action extends FileGSTR1Dialog {
),
() => {
frappe.show_alert(__("Resetting GSTR-1 data"));
this.perform_gstr1_action(action, () =>
this.check_action_status_with_retry(action)
this.perform_gstr1_action(
action,
() => this.check_action_status_with_retry(action),
{ is_nil_return: this.frm.doc.file_nil_gstr1 }
);
}
);
Expand Down
45 changes: 45 additions & 0 deletions india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,45 @@ def get_invoice_values(self, invoice):
GSTR1_DataField.CESS.value: invoice.total_cess_amount,
}

def round_values(self, data):
"""
Progressively round off the values in the data
to ensure that the total values match the sum of the individual values
"""

if isinstance(data[0], list):
for row in data:
self.round_values(row)

fields = (
GSTR1_DataField.TAXABLE_VALUE.value,
GSTR1_DataField.IGST.value,
GSTR1_DataField.CGST.value,
GSTR1_DataField.SGST.value,
GSTR1_DataField.CESS.value,
)

for field in fields:
if field not in data[0]:
continue

differece = 0
last_row_with_value = None

for row in data:
if not row[field]: # zero values
continue

rounded = flt(row[field], 2)
differece += row[field] - rounded

row[field] = flt(rounded, 2)

last_row_with_value = row

if flt(differece, 2) != 0:
last_row_with_value[field] += differece


class GSTR1BooksData(BooksDataMapper):
def __init__(self, filters):
Expand Down Expand Up @@ -2372,6 +2411,12 @@ def prepare_mapped_data(self):
if data:
prepared_data[category] = data

for data in prepared_data.values():
if not isinstance(data, dict):
continue

self.round_values(list(data.values()))

return prepared_data

def prepare_document_issued_data(self):
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/public/js/gst_api_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Object.assign(india_compliance, {
],
primary_action_label: __("Submit"),
primary_action(values) {
resolve(values.otp);
resolve(values.otp.trim());
prompt.hide();
},
secondary_action_label: __("Resend OTP"),
Expand Down

0 comments on commit 4920eff

Please sign in to comment.