Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add comment in gst return log for backdated transactions #2656

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions india_compliance/gst_india/overrides/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def validate(doc, method=None):
return

if doc.party_type == "Customer":
validate_backdated_transaction(doc)

# Presume is export with GST if GST accounts are present
doc.is_export_with_gst = 1
validate_transaction_for_advance_payment(doc, method)
Expand All @@ -98,6 +96,9 @@ def validate(doc, method=None):


def on_submit(doc, method=None):
if doc.party_type == "Customer":
validate_backdated_transaction(doc)

make_gst_revesal_entry_from_advance_payment(doc)


Expand All @@ -112,7 +113,7 @@ def before_cancel(doc, method=None):
validate_backdated_transaction(doc, action="cancel")


def validate_backdated_transaction(doc, action="create"):
def validate_backdated_transaction(doc, action="submit"):
for row in doc.taxes:
if row.gst_tax_type in TAX_TYPES and row.tax_amount != 0:
_validate_backdated_transaction(doc, action=action)
Expand Down
3 changes: 2 additions & 1 deletion india_compliance/gst_india/overrides/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def validate(doc, method=None):

gst_settings = frappe.get_cached_doc("GST Settings")

validate_backdated_transaction(doc, gst_settings)
validate_invoice_number(doc)
validate_credit_debit_note(doc)
validate_fields_and_set_status_for_e_invoice(doc, gst_settings)
Expand Down Expand Up @@ -139,6 +138,8 @@ def is_shipping_address_in_india(doc):


def on_submit(doc, method=None):
validate_backdated_transaction(doc)

if getattr(doc, "_submitted_from_ui", None) or validate_transaction(doc) is False:
return

Expand Down
43 changes: 38 additions & 5 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from frappe import _, bold
from frappe.contacts.doctype.address.address import get_default_address
from frappe.model.utils import get_fetch_values
from frappe.utils import cint, flt, format_date
from frappe.utils import cint, flt, format_date, get_link_to_form, getdate
from erpnext.controllers.accounts_controller import get_taxes_and_charges

from india_compliance.gst_india.constants import (
Expand All @@ -20,7 +20,10 @@
from india_compliance.gst_india.doctype.gst_settings.gst_settings import (
restrict_gstr_1_transaction_for,
)
from india_compliance.gst_india.doctype.gstin.gstin import get_and_validate_gstin_status
from india_compliance.gst_india.doctype.gstin.gstin import (
get_and_validate_gstin_status,
get_gstr_1_filed_upto,
)
from india_compliance.gst_india.utils import (
get_all_gst_accounts,
get_gst_account_gst_tax_type_map,
Expand Down Expand Up @@ -660,17 +663,47 @@ def get_source_state_code(doc):
return (doc.supplier_gstin or doc.company_gstin)[:2]


def validate_backdated_transaction(doc, gst_settings=None, action="create"):
if gstr_1_filed_upto := restrict_gstr_1_transaction_for(
def validate_backdated_transaction(doc, gst_settings=None, action="submit"):
gst_settings = gst_settings or frappe.get_cached_doc("GST Settings")

gstr_1_filed_upto = restrict_gstr_1_transaction_for(
doc.posting_date, doc.company_gstin, gst_settings
):
)

if gstr_1_filed_upto:
frappe.throw(
_(
"You are not allowed to {0} {1} as GSTR-1 has been filed upto {2}"
).format(action, doc.doctype, frappe.bold(format_date(gstr_1_filed_upto))),
title=_("Restricted Changes"),
)

gstr_1_filed_upto = get_gstr_1_filed_upto(doc.company_gstin)
if not gstr_1_filed_upto or getdate(doc.posting_date) > gstr_1_filed_upto:
return

gst_return_log_name = get_gst_return_log_name(doc.company_gstin, gstr_1_filed_upto)
if not gst_return_log_name:
return

gst_return_log = frappe.get_doc("GST Return Log", gst_return_log_name)
gst_return_log.add_comment(
"Comment",
f"{doc.doctype} : {get_link_to_form(doc.doctype, doc.name)} has been {action} by {frappe.session.user}",
)


def get_gst_return_log_name(company_gstin, gstr_1_filed_upto):
filters = {
"return_period": f"{gstr_1_filed_upto.month:02d}{gstr_1_filed_upto.year}",
"gstin": company_gstin,
}

if doc_name := frappe.db.exists("GST Return Log", filters):
return doc_name

return None


def validate_hsn_codes(doc, throw=False, message=None):
validate_hsn_code, valid_hsn_length = get_hsn_settings()
Expand Down