Skip to content

Commit

Permalink
Merge pull request #2247 from resilient-tech/mergify/bp/version-14-ho…
Browse files Browse the repository at this point in the history
…tfix/pr-2245

fix: `DoesNotExistError` while processing return info (backport #2245)
  • Loading branch information
mergify[bot] committed Jun 13, 2024
2 parents 4db8111 + 8d241c6 commit 9fd9877
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 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 @@ -141,6 +141,10 @@ frappe.ui.form.on(DOCTYPE, {
);
});

frappe.realtime.on("show_message", message => {
frappe.msgprint(message);
});

frappe.realtime.on("gstr1_generation_failed", message => {
const { error, filters } = message;
let alert = `GSTR-1 Generation Failed for ${filters.company_gstin} - ${filters.month_or_quarter} - ${filters.year}.<br/><br/>${error}`;
Expand Down
39 changes: 29 additions & 10 deletions india_compliance/gst_india/doctype/gstr_1_log/gstr_1_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime

import frappe
from frappe import unscrub
from frappe import _, unscrub
from frappe.model.document import Document
from frappe.utils import flt, get_datetime, get_datetime_str, get_last_day, getdate

Expand Down Expand Up @@ -503,7 +503,7 @@ def generate_gstr1_data(self, filters, callback=None):
data = {}

# APIs Disabled
if not self.is_gstr1_api_enabled():
if not self.is_gstr1_api_enabled(warn_for_missing_credentials=True):
return self.generate_only_books_data(data, filters, callback)

# APIs Enabled
Expand Down Expand Up @@ -773,15 +773,33 @@ def remove_json_for(self, file_field):
self.remove_json_for("unfiled")

# GSTR 1 UTILITY
def is_gstr1_api_enabled(self, settings=None):
def is_gstr1_api_enabled(self, settings=None, warn_for_missing_credentials=False):
if not settings:
settings = frappe.get_cached_doc("GST Settings")

return (
is_production_api_enabled(settings)
and settings.compare_gstr_1_data
and settings.has_valid_credentials(self.gstin, "Returns")
)
if not is_production_api_enabled(settings):
return False

if not settings.compare_gstr_1_data:
return False

if not settings.has_valid_credentials(self.gstin, "Returns"):
if warn_for_missing_credentials:
frappe.publish_realtime(
"show_message",
dict(
message=_(
"Credentials are missing for GSTIN {0} for service"
" Returns in GST Settings"
).format(self.gstin),
title=_("Missing Credentials"),
),
user=frappe.session.user,
)

return False

return True

def is_sek_needed(self, settings=None):
if not self.is_gstr1_api_enabled(settings):
Expand Down Expand Up @@ -850,8 +868,9 @@ def process_gstr_1_returns_info(company, gstin, response):
)

# update gstr-1 filed upto
gstin_doc = frappe.get_doc("GSTIN", gstin)
if not gstin_doc:
if frappe.db.exists("GSTIN", gstin):
gstin_doc = frappe.get_doc("GSTIN", gstin)
else:
gstin_doc = frappe.new_doc("GSTIN", gstin=gstin, status="Active")

def _update_gstr_1_filed_upto(filing_date):
Expand Down

0 comments on commit 9fd9877

Please sign in to comment.