Skip to content

Conversation

@ljain112
Copy link
Collaborator

@ljain112 ljain112 commented Dec 3, 2025

closes: #44219

@ljain112 ljain112 force-pushed the feat-not-applicable-tax branch from 0e7786d to 144e0e1 Compare December 3, 2025 07:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Warning

Rate limit exceeded

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

⌛ 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7a5cb1f and dd35e1e.

📒 Files selected for processing (2)
  • erpnext/controllers/taxes_and_totals.py (4 hunks)
  • erpnext/public/js/controllers/taxes_and_totals.js (4 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces functionality to mark taxes as "not applicable" to specific items. A new not_applicable checkbox field is added to the Item Tax Template Detail doctype. The frontend and backend tax calculation logic is updated to recognize a sentinel value (NOT_APPLICABLE_TAX = "N/A") and short-circuit tax computations when this value is encountered. When applying item tax templates, the not_applicable flag is propagated to the calculation system, preventing tax inclusion for marked items. A float conversion for tax rates is also added in the buying controller.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

Areas requiring extra attention:

  • erpnext/controllers/taxes_and_totals.py — Multiple methods modified to handle the NOT_APPLICABLE_TAX sentinel; verify that short-circuit logic is correctly applied in all tax calculation paths (get_current_tax_fraction, _get_tax_rate, get_current_tax_and_net_amount).
  • erpnext/public/js/controllers/taxes_and_totals.js — Parallel changes to frontend tax calculations; ensure consistency with backend implementation, particularly in add_taxes_from_item_tax_template and tax fraction/amount calculations.
  • erpnext/stock/get_item_details.py — Ensure the propagation of not_applicable flag from template to item tax map is complete and doesn't miss edge cases.
  • erpnext/controllers/buying_controller.py — Verify that the float conversion of rate doesn't introduce precision issues or affect existing calculations downstream.

Suggested reviewers

  • ruthra-kumar
  • rohitwaghchaure
  • mihir-kandoi
  • vorasmit

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The pull request description is a template with no author-provided details about the changes or the feature being implemented. Add a meaningful description explaining what the 'not applicable' tax feature does, why it's needed, and provide examples or screenshots to clarify the implementation.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add support for 'not applicable' tax in item tax templates' directly and clearly summarizes the main change across all modified files, which implement support for a new 'not applicable' tax option in item tax templates.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
erpnext/controllers/taxes_and_totals.py (2)

29-29: Centralize NOT_APPLICABLE_TAX usage across modules / layers

Defining a single NOT_APPLICABLE_TAX = "N/A" constant here is good, but the same sentinel is also used in other Python modules and in the JS controller in this PR. Consider either:

  • Importing this constant wherever possible on the Python side, and
  • Adding a short comment noting that JS must use the same literal,

to reduce the risk of future drift between back-end and front-end or between modules.


582-623: Confirm omission of N/A taxes from item‑wise tax details is desired

The early return when tax_rate == NOT_APPLICABLE_TAX happens before set_item_wise_tax is called, so for “N/A” taxes:

  • current_tax_amount and current_net_amount remain zero (no effect on totals), and
  • No row is appended to self.doc._item_wise_tax_details, so get_itemised_tax / reports won’t show this tax at all for that item.

This behavior seems consistent with “not applicable” (tax is ignored rather than shown as 0%), but it does mean item-wise tax breakup will not explicitly show an N/A entry. Please confirm this matches functional expectations for reports and UI; otherwise, you may want to record a zero-amount row with a special rate instead.

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7bca3bb and 0e7786d.

📒 Files selected for processing (7)
  • erpnext/accounts/doctype/item_tax_template_detail/item_tax_template_detail.json (2 hunks)
  • erpnext/accounts/doctype/item_tax_template_detail/item_tax_template_detail.py (1 hunks)
  • erpnext/controllers/accounts_controller.py (2 hunks)
  • erpnext/controllers/buying_controller.py (2 hunks)
  • erpnext/controllers/taxes_and_totals.py (4 hunks)
  • erpnext/public/js/controllers/taxes_and_totals.js (5 hunks)
  • erpnext/stock/get_item_details.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-09T06:59:10.528Z
Learnt from: ljain112
Repo: frappe/erpnext PR: 49963
File: erpnext/accounts/doctype/journal_entry/journal_entry.py:0-0
Timestamp: 2025-10-09T06:59:10.528Z
Learning: In erpnext/accounts/doctype/journal_entry/journal_entry.py, the validate() method calls validate_multi_currency() before apply_tax_withholding(). The validate_multi_currency() method internally calls set_exchange_rate(), so exchange rates are properly set on all account rows before TDS calculations occur in apply_tax_withholding().

Applied to files:

  • erpnext/controllers/accounts_controller.py
🧬 Code graph analysis (1)
erpnext/stock/get_item_details.py (1)
erpnext/public/js/controllers/taxes_and_totals.js (1)
  • NOT_APPLICABLE_TAX (5-5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Patch Test
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Summary
🔇 Additional comments (9)
erpnext/accounts/doctype/item_tax_template_detail/item_tax_template_detail.json (1)

9-11: Item Tax Template “Not Applicable” flag is well‑integrated

Field definition (Check with default "0", clear description, and inclusion in field_order / list view) and row_format: "Dynamic" all look consistent with intended usage and the rest of the DocType. No further changes needed here.

Also applies to: 26-33, 45-45

erpnext/accounts/doctype/item_tax_template_detail/item_tax_template_detail.py (1)

14-23: Type hint matches new DocType field

not_applicable: DF.Check correctly reflects the new Check field and keeps the auto‑generated typing block consistent. Nothing to change here.

erpnext/controllers/buying_controller.py (1)

21-21: Buying valuation correctly skips “not applicable” item taxes

The additional check in get_item_tax_amount to continue when rate == NOT_APPLICABLE_TAX cleanly avoids treating "N/A" as a 0% rate while excluding those lines from valuation tax. This aligns with how NOT_APPLICABLE_TAX is handled elsewhere and maintains backward compatibility for numeric rates.

Also applies to: 502-519

erpnext/public/js/controllers/taxes_and_totals.js (1)

4-6: Client-side NOT_APPLICABLE_TAX handling is consistent and safe

The JS changes correctly introduce a scoped NOT_APPLICABLE_TAX constant and:

  • Short‑circuit get_current_tax_fraction and get_current_tax_amount when the per‑item rate is "N/A", avoiding numeric operations on the sentinel and excluding those taxes from per‑item tax math.
  • Propagate the sentinel through _get_tax_rate without converting it, while still formatting numeric rates as before.
  • Skip creating header‑level tax rows in add_taxes_from_item_tax_template for "N/A" entries.

This mirrors the server‑side semantics and keeps the sentinel confined to item_tax_rate maps, so overall the client behaviour looks correct.

Also applies to: 295-307, 331-341, 383-397, 530-538

erpnext/stock/get_item_details.py (1)

24-24: Verify non‑numeric rate handling for as_json=False callers

The NOT_APPLICABLE_TAX sentinel propagation in get_item_tax_map is consistent with the pipeline's treatment (Python and JS both handle this case). However, when as_json=False, callers may now receive string values ("N/A") instead of exclusively numeric rates. Search the codebase for uses of get_item_tax_map(..., as_json=False) to confirm whether external or custom consumers depend on numeric-only values in item_tax_map; if so, this contract change should be documented.

erpnext/controllers/accounts_controller.py (1)

66-66: Verify if taxes_and_totals.py imports from accounts_controller.py to confirm circular dependency risk

The suggestion to move NOT_APPLICABLE_TAX import into the function body assumes that erpnext.controllers.taxes_and_totals imports helpers from accounts_controller.py. Without access to the actual codebase, this cannot be confirmed. If such imports exist, the module-level import could indeed reintroduce a circular dependency. If they do not exist, the module-level import is safe.

Verify the dependency chain in taxes_and_totals.py to determine if this refactoring is necessary.

erpnext/controllers/taxes_and_totals.py (3)

22-26: Imports align item tax template validation with shared utilities

Using ItemDetailsCtx, _get_item_tax_template, and get_item_tax_map from erpnext.stock.get_item_details keeps item tax validation/mapping consistent with the central item-details logic and avoids duplication. The imports are used correctly in validate_item_tax_template and update_item_tax_map.


341-377: Short‑circuit for NOT_APPLICABLE_TAX in inclusive tax fraction is correct

The early return when tax_rate == NOT_APPLICABLE_TAX ensures that:

  • No arithmetic is performed on the "N/A" sentinel, and
  • Inclusive tax fractions and per‑qty inclusive amounts treat not-applicable taxes as if they don’t exist for that item,

which matches the intended semantics for per-item “not applicable” taxes.


378-387: Verify other consumers of item_tax_rate for "N/A" compatibility

_get_tax_rate now propagates the "N/A" sentinel from item_tax_map instead of coercing it to a float. This means item.item_tax_rate JSON can now contain non-numeric values. While the two call sites within this class guard against "N/A", a comprehensive search across the codebase is needed to ensure no other consumers perform flt() or numeric operations on item_tax_rate without checking for the sentinel value first.

Scan the codebase for all usages of item_tax_rate to identify any potential incompatibilities.

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.90%. Comparing base (88e94aa) to head (dd35e1e).
⚠️ Report is 30 commits behind head on develop.

Files with missing lines Patch % Lines
erpnext/controllers/taxes_and_totals.py 61.53% 5 Missing ⚠️
erpnext/stock/get_item_details.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #50898   +/-   ##
========================================
  Coverage    78.89%   78.90%           
========================================
  Files         1174     1174           
  Lines       119302   119352   +50     
========================================
+ Hits         94123    94172   +49     
- Misses       25179    25180    +1     
Files with missing lines Coverage Δ
...em_tax_template_detail/item_tax_template_detail.py 100.00% <ø> (ø)
erpnext/controllers/buying_controller.py 84.47% <100.00%> (+0.02%) ⬆️
erpnext/stock/get_item_details.py 84.71% <75.00%> (-0.08%) ⬇️
erpnext/controllers/taxes_and_totals.py 95.34% <61.53%> (-0.67%) ⬇️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accounts buying needs-tests This PR needs automated unit-tests. stock

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Net amount calculated incorrectly

1 participant