Skip to content

Commit

Permalink
fix: changes as per review
Browse files Browse the repository at this point in the history
(cherry picked from commit 7752634)
  • Loading branch information
vorasmit authored and mergify[bot] committed Mar 21, 2024
1 parent afd8192 commit b183b86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
42 changes: 32 additions & 10 deletions india_compliance/gst_india/overrides/address.py
Expand Up @@ -9,23 +9,45 @@
validate_pincode,
)

def set_gstin_and_gstCategory(doc, method=None):
links = doc.links

for link in links:
def update_party_gstin_and_gst_category(doc, method=None):
"""
Update GSTIN and GST Category for Customer and Supplier based on Address.
"""
if not doc.gstin:
return

if not doc.has_value_changed("gstin"):
return

party_address_updated = False
for link in doc.links:
doctype = link.link_doctype
docname = link.link_name

if doctype not in ['Customer','Supplier']:
if doctype not in ["Customer", "Supplier"]:
continue

gstin = doc.gstin
if gstin:
frappe.db.set_value(doctype,docname,"gstin",gstin)
party_gst_category, party_pan = frappe.db.get_value(
doctype, docname, ["gst_category", "pan"]
)
if party_gst_category != "Unregistered":
continue

address_pan = doc.gstin[2:12]
if party_pan and party_pan != address_pan:
continue

frappe.db.set_value(
doctype,
docname,
{"gstin": doc.gstin, "gst_category": doc.gst_category, "pan": address_pan},
)

party_address_updated = True

gst_category = doc.gst_category
if gst_category:
frappe.db.set_value(doctype, docname, "gst_category", gst_category)
if party_address_updated:
frappe.msgprint(_("Party GSTIN is updated based on Address"), alert=True)


def validate(doc, method=None):
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/hooks.py
Expand Up @@ -77,8 +77,8 @@
"india_compliance.gst_india.overrides.address.validate",
"india_compliance.gst_india.overrides.party.set_docs_with_previous_gstin",
],
"before_save": [
"india_compliance.gst_india.overrides.address.set_gstin_and_gstCategory"
"on_update": [
"india_compliance.gst_india.overrides.address.update_party_gstin_and_gst_category"
],
},
"Company": {
Expand Down

0 comments on commit b183b86

Please sign in to comment.