Skip to content

Commit

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

fix: avoid duplicate address keys in gstin info based on key priority (backport #2094)
  • Loading branch information
mergify[bot] authored May 2, 2024
2 parents 8a57a86 + 8d6f43b commit 30b47d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions india_compliance/gst_india/utils/gstin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"URP": "Unregistered",
}

# order of address keys is important
KEYS_TO_SANITIZE = ("dst", "stcd", "pncd", "bno", "flno", "bnm", "st", "loc", "city")
KEYS_TO_FILTER_DUPLICATES = frozenset(("dst", "bnm", "st", "loc", "city"))
CHARACTERS_TO_STRIP = f"{whitespace},"


@frappe.whitelist()
def get_gstin_info(gstin, *, throw_error=True):
Expand Down Expand Up @@ -121,12 +126,21 @@ def _get_address(address):

def _extract_address_lines(address):
"""merge and divide address into exactly two lines"""

unique_values = set()
for key, value in address.items():
value = value.strip(f"{whitespace},")
address[key] = value if value not in unique_values else None
unique_values.add(value)

for key in KEYS_TO_SANITIZE:
value = address.get(key, "").strip(CHARACTERS_TO_STRIP)

if key not in KEYS_TO_FILTER_DUPLICATES:
address[key] = value
continue

if value not in unique_values:
address[key] = value
unique_values.add(value)
continue

address[key] = ""

address_line1 = ", ".join(
titlecase(value)
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/utils/test_gstin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestGstinInfo(unittest.TestCase):
"addr": {
"bnm": "",
"bno": "8-A",
"city": "",
"city": "Vadodara",
"dst": "Vadodara",
"flno": "Saimee society No.2",
"lg": "",
Expand Down

0 comments on commit 30b47d1

Please sign in to comment.