Skip to content

Commit

Permalink
fix: throw error when not able to cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Oct 16, 2024
1 parent b7933ef commit 21f195c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 4 additions & 2 deletions india_compliance/gst_india/overrides/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ def before_cancel(doc, method=None):


def on_cancel(doc, method=None):
if not doc.irn:
return

values = {
"irn": doc.irn,
"reason": "Data Entry Mistake",
"ewaybill": doc.ewaybill or "",
"remark": "",
}
if doc.irn:
cancel_e_invoice(doc.name, values, show_msg=False)
cancel_e_invoice(doc.name, values, show_msg=False)


def is_e_waybill_applicable(doc, gst_settings=None):
Expand Down
20 changes: 7 additions & 13 deletions india_compliance/gst_india/utils/e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ def cancel_e_invoice(docname, values, show_msg=True):
doc = load_doc("Sales Invoice", docname, "cancel")
values = frappe.parse_json(values)

valid = validate_if_e_invoice_can_be_cancelled(doc, throw=show_msg)
if not valid:
return
validate_if_e_invoice_can_be_cancelled(doc)

if doc.get("ewaybill"):
_cancel_e_waybill(doc, values, show_msg)
Expand Down Expand Up @@ -532,26 +530,22 @@ def validate_taxable_item(doc, throw=True):
)


def validate_if_e_invoice_can_be_cancelled(doc, throw=True):
def validate_if_e_invoice_can_be_cancelled(doc):
if not doc.irn:
frappe.throw(_("IRN not found"), title=_("Error Cancelling e-Invoice"))

# this works because we do run_onload in load_doc above
acknowledged_on = doc.get_onload().get("e_invoice_info", {}).get("acknowledged_on")

is_cancellation_allowed = (
acknowledged_on
and add_to_date(get_datetime(acknowledged_on), days=1, as_datetime=True)
>= get_datetime()
)

if throw and not is_cancellation_allowed:
if (
not acknowledged_on
or add_to_date(get_datetime(acknowledged_on), days=1, as_datetime=True)
< get_datetime()
):
frappe.throw(
_("e-Invoice can only be cancelled upto 24 hours after it is generated")
)

return is_cancellation_allowed


def retry_e_invoice_e_waybill_generation():
settings = frappe.get_cached_doc("GST Settings")
Expand Down

0 comments on commit 21f195c

Please sign in to comment.