Skip to content

Commit

Permalink
fix: fixed aadhar card number
Browse files Browse the repository at this point in the history
(cherry picked from commit 7f6d4da)
  • Loading branch information
Sanket322 authored and mergify[bot] committed Aug 22, 2024
1 parent d5b8e27 commit 78eff3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 58 deletions.
71 changes: 14 additions & 57 deletions india_compliance/gst_india/overrides/party.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import random

import requests

Expand Down Expand Up @@ -169,68 +168,26 @@ def make_address(doc):
).insert()


multiplication_table = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
]

permutation_table = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8],
]

inverse_table = [0, 4, 3, 2, 1, 5, 6, 7, 8, 9]


def verhoeff_checksum(number: str) -> int:
"""Calculate the Verhoeff checksum digit."""
c = 0
n = len(number)
for i in range(n):
c = multiplication_table[c][
permutation_table[(i + 1) % 8][int(number[n - i - 1])]
]
return inverse_table[c]


def generate_aadhaar_number():
"""Generate a valid Aadhaar number using the Verhoeff algorithm."""
base_number = "".join([str(random.randint(0, 9)) for _ in range(11)])
check_digit = verhoeff_checksum(base_number)
return base_number + str(check_digit)


@frappe.whitelist()
def validate_pancard_status(pan):
aadhaar_number = generate_aadhaar_number()
url = "https://eportal.incometax.gov.in/iec/servicesapi/getEntity"
payload = {
"aadhaarNumber": aadhaar_number,
"aadhaarNumber": "887598175965", # this is random generated aadhaar_number
"pan": pan,
"preLoginFlag": "Y",
"serviceName": "linkAadhaarPreLoginService",
}
response = requests.post(url, json=payload)
messages = response.json().get("messages", [])

if messages and "linked to some other Aadhaar" in messages[0].get("desc", ""):
return "Linked"
elif messages and "PAN does not exist." in messages[0].get("desc", ""):
return "Invalid PAN"
elif messages and "Individual taxpayers" in messages[0].get("desc", ""):
return "Not an Individual Taxpayer"
return ""
messages = response.json().get("messages")
if not messages:
return ""

error_code_desc_map = {
"EF40124": "Linked", # pan linked to given aadhar card
"EF40026": "Linked", # pan linked but not to given aadhar card
"EF40089": "Invalid PAN",
"EF40119": "Not an Individual Taxpayer",
"EF40024": "Not-Linked",
}

return error_code_desc_map.get(messages[0].get("code", ""), "")
2 changes: 1 addition & 1 deletion india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Object.assign(india_compliance, {

if (!message || message == "") return field.set_description("");

const STATUS_COLORS = { 'Linked': "green", 'Not-Linked': "red", "Not an Individual Taxpayer" : "red",
const STATUS_COLORS = { 'Linked': "green", 'Not-Linked': "red", "Not an Individual Taxpayer" : "green",
"Invalid PAN" : "red" };
pan_status = `<div class="d-flex indicator ${STATUS_COLORS[message] || "orange"}">
Status:&nbsp;<strong>${message}</strong>
Expand Down

0 comments on commit 78eff3a

Please sign in to comment.