Skip to content

Commit

Permalink
fix: display last updated time for pan status
Browse files Browse the repository at this point in the history
(cherry picked from commit 921aafb)
  • Loading branch information
Sanket322 authored and mergify[bot] committed Aug 22, 2024
1 parent 9b15669 commit 900c959
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
11 changes: 9 additions & 2 deletions india_compliance/gst_india/doctype/pan/pan.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_pan_status(pan, force_update=False):
return (pan_doc.pan_status, pan_doc.last_updated_on)


def fetch_and_update_pan_status(pan, throw):
def fetch_and_update_pan_status(pan, throw, duplicate=False):
pan_check_result = fetch_pan_status(pan, throw)

if not pan_check_result:
Expand All @@ -76,7 +76,14 @@ def fetch_and_update_pan_status(pan, throw):
"EF40077": "", # Invalid Aadhaar number
}

status = error_code_desc_map.get(pan_check_result.get("code", ""), "")
error_code = pan_check_result.get("code", "")

# if invalid Aadhaar number then check pan status one more time
if not duplicate and error_code == "EF40077":
return fetch_and_update_pan_status(pan, throw, duplicate=True)

status = error_code_desc_map.get(error_code, "")

if not status:
return

Expand Down
49 changes: 20 additions & 29 deletions india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,43 +120,34 @@ Object.assign(india_compliance, {
args: { pan, force_update },
});

if (!message) {
message = ["", frappe.datetime.now_datetime()];
}
if (!message) return;

const [pan_status, datetime] = message;
const STATUS_COLORS = {
Valid: "green",
"Not Linked": "red",
Invalid: "red",
};
let pan_desc;

if (!pan_status) {
const user_date = frappe.datetime.str_to_user(datetime);
const pretty_date = frappe.datetime.prettyDate(datetime);

pan_desc = $(`<div class="text-right">
<span class="pan-last-updated">
<span title="${user_date}">
${datetime ? "updated " + pretty_date : ""}
</span>
<svg class="icon icon-sm refresh-pan" style="cursor: pointer;">
<use href="#icon-refresh"></use>
</svg>
</span>
</div>`);

pan_desc.find(".refresh-pan").on("click", async function () {
await india_compliance.set_pan_status(field, true);
});
} else {
pan_desc = `<div class="d-flex indicator ${
STATUS_COLORS[pan_status] || "orange"
}">
Status:&nbsp;<strong>${pan_status}</strong>
</div>`;
}
const user_date = frappe.datetime.str_to_user(datetime);
const pretty_date = frappe.datetime.prettyDate(datetime);
const pan_desc = $(
`<div class="d-flex indicator ${STATUS_COLORS[pan_status] || "orange"}">
Status:&nbsp;<strong>${pan_status}</strong>
<span class="text-right ml-auto">
<span title="${user_date}">
${datetime ? "updated " + pretty_date : ""}
</span>
<svg class="icon icon-sm refresh-pan" style="cursor: pointer;">
<use href="#icon-refresh"></use>
</svg>
</span>
</div>`
);

pan_desc.find(".refresh-pan").on("click", async function () {
await india_compliance.set_pan_status(field, true);
});
return field.set_description(pan_desc);
},

Expand Down

0 comments on commit 900c959

Please sign in to comment.