Skip to content

fix: update itc claim period from frontend on change of posting date or company gstin#4238

Draft
ljain112 wants to merge 2 commits into
resilient-tech:developfrom
ljain112:itc-claim-period-changes
Draft

fix: update itc claim period from frontend on change of posting date or company gstin#4238
ljain112 wants to merge 2 commits into
resilient-tech:developfrom
ljain112:itc-claim-period-changes

Conversation

@ljain112

Copy link
Copy Markdown
Member

Update itc claim period from the frontend on change of posting date or company GSTIN if invalid.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ljain112 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 24 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c1745c59-e52a-4eb3-a7fa-2f4ba86ab36b

📥 Commits

Reviewing files that changed from the base of the PR and between 61b18cb and 7eac000.

📒 Files selected for processing (3)
  • india_compliance/gst_india/client_scripts/purchase_invoice.js
  • india_compliance/gst_india/doctype/bill_of_entry/bill_of_entry.js
  • india_compliance/public/js/utils.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ljain112 ljain112 force-pushed the itc-claim-period-changes branch from 068dc3a to fe10aea Compare April 23, 2026 13:30
@greptile-apps

greptile-apps Bot commented Apr 23, 2026

Copy link
Copy Markdown

Confidence Score: 4/5

Safe to merge after fixing the missing try/finally guard reset; the feature otherwise works correctly for the happy path.

One P1 defect: a transient API error permanently deadlocks the guard flag, silently breaking ITC period auto-update for the rest of the form session. The fix is straightforward (wrap in try/finally).

india_compliance/public/js/utils.js — the update_itc_claim_period function needs a try/finally around the API call to ensure the guard flag is always released.

Important Files Changed

Filename Overview
india_compliance/public/js/utils.js New update_itc_claim_period helper added; guard flag is not reset in a finally block, so an API error permanently disables auto-update for the form session.
india_compliance/gst_india/client_scripts/purchase_invoice.js Adds posting_date and company_gstin handlers to call update_itc_claim_period; existing gst_category handler is preserved. Change looks correct.
india_compliance/gst_india/doctype/bill_of_entry/bill_of_entry.js Adds posting_date/company_gstin handlers and an explicit update_itc_claim_period call at the end of the company handler; await added to set_value calls. The in-flight guard prevents a double API call in the normal case.

Reviews (2): Last reviewed commit: "fix: correct flag position" | Re-trigger Greptile

Comment thread india_compliance/public/js/utils.js Outdated
const current_period = frm.doc.itc_claim_period;
if (current_period && valid_periods?.includes(current_period)) return;

const period = valid_periods?.[1];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Defaulting to index [1] instead of [0]

The function selects valid_periods?.[1] (the second element) as the replacement period. If the list has only one element — a valid edge case when posting date is near the boundary of valid periods — valid_periods[1] will be undefined, and itc_claim_period won't be updated even though valid_periods[0] is a valid choice. Was [0] (most recent / first valid period) intended here?

@ljain112

Copy link
Copy Markdown
Member Author

@greptileai

Comment on lines +382 to +395
if (frm.__updating_itc_claim_period) return;
frm.__updating_itc_claim_period = true;

await frappe.after_ajax();

const { message: valid_periods } = await frappe.call({
method: "india_compliance.gst_india.utils.itc_claim.get_itc_period_options",
args: {
company_gstin: frm.doc.company_gstin,
posting_date: frm.doc.posting_date,
},
});

frm.__updating_itc_claim_period = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Guard flag not reset on API error

If frappe.call() rejects (network failure, server error, etc.), frm.__updating_itc_claim_period is never reset to false. Every subsequent call to update_itc_claim_period will hit the early-return guard and silently do nothing for the lifetime of the form, meaning a transient error permanently breaks ITC period auto-update.

Suggested change
if (frm.__updating_itc_claim_period) return;
frm.__updating_itc_claim_period = true;
await frappe.after_ajax();
const { message: valid_periods } = await frappe.call({
method: "india_compliance.gst_india.utils.itc_claim.get_itc_period_options",
args: {
company_gstin: frm.doc.company_gstin,
posting_date: frm.doc.posting_date,
},
});
frm.__updating_itc_claim_period = false;
if (frm.__updating_itc_claim_period) return;
frm.__updating_itc_claim_period = true;
try {
await frappe.after_ajax();
const { message: valid_periods } = await frappe.call({
method: "india_compliance.gst_india.utils.itc_claim.get_itc_period_options",
args: {
company_gstin: frm.doc.company_gstin,
posting_date: frm.doc.posting_date,
},
});
} finally {
frm.__updating_itc_claim_period = false;
}

@codacy-production

codacy-production Bot commented Apr 23, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 18 complexity

Metric Results
Complexity 18

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ljain112

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ljain112 ljain112 force-pushed the itc-claim-period-changes branch from 7eac000 to 8964e6f Compare June 15, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant