Skip to content

Conversation

@ljain112
Copy link
Member

@ljain112 ljain112 commented Oct 27, 2025

Issue: Error on Sales RCM Credit Note e-invoice generation.

image

Frappe Support Issue: https://support.frappe.io/helpdesk/tickets/51639?view=VIEW-HD+Ticket-771

Summary by CodeRabbit

  • Bug Fixes
    • Corrected e-invoice total value for reverse-charge transactions to use the absolute value of the taxable amount and apply rounding to two decimals, ensuring accurate and consistent invoice totals.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

When reverse charge is active in GST e-invoice calculations, total_value is now computed as the absolute rounded value of taxable_value (rounded to 2 decimals) instead of using the raw taxable_value.

Changes

Cohort / File(s) Summary
E-invoice calculation fix
india_compliance/gst_india/utils/e_invoice.py
In update_item_details, set total_value to the absolute rounded value of taxable_value (rounded to 2 decimals) when reverse charge is active instead of using the raw taxable_value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify rounding to 2 decimals and absolute-value semantics match GST reverse-charge requirements.
  • Check downstream consumers of total_value for any expectations about sign or precision.
  • Update or confirm unit tests cover reverse-charge calculation path.

Poem

🐰 Hop over numbers, neat and spry,

Rounded hops now reach the sky,
Absolute steps, tidy and clear,
Invoices hum with cheery cheer,
A rabbit's nod—precision here! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: absolute item total value for rcm invoice" is directly related to and clearly summarizes the main change in the pull request. The title specifically mentions "absolute item total value," which accurately reflects the core modification where total_value is now set to the absolute rounded value of taxable_value under reverse-charge scenarios. The term "rcm invoice" correctly identifies the context as RCM (Reverse Charge Mechanism) invoices, and the prefix "fix:" appropriately indicates this addresses a bug fix for Sales RCM Credit Note e-invoice generation. The title is concise, uses specific terminology, and would enable teammates to quickly understand the primary purpose of this changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-total-item-rcm

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f98524b and c0b3916.

📒 Files selected for processing (1)
  • india_compliance/gst_india/utils/e_invoice.py (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: vorasmit
Repo: resilient-tech/india-compliance PR: 3344
File: india_compliance/gst_india/report/account_wise_summary/account_wise_summary.py:81-87
Timestamp: 2025-04-25T10:12:24.584Z
Learning: When processing taxes in GST India reports, charges after GST rows with charge_type "On Previous Row Total" should not be used to compute taxable value, so a break statement is used to exit the tax processing loop once such a row is encountered.
📚 Learning: 2025-07-22T11:45:43.432Z
Learnt from: karm1000
Repo: resilient-tech/india-compliance PR: 3532
File: india_compliance/gst_india/utils/e_waybill.py:327-336
Timestamp: 2025-07-22T11:45:43.432Z
Learning: In the e-waybill update functions (india_compliance/gst_india/utils/e_waybill.py), fields like place_of_change and state use hardcoded "-" values in old_values dictionaries because these values are not stored in the system, so there's no way to retrieve the actual previous values.

Applied to files:

  • india_compliance/gst_india/utils/e_invoice.py
📚 Learning: 2025-06-25T08:19:02.607Z
Learnt from: karm1000
Repo: resilient-tech/india-compliance PR: 3354
File: india_compliance/gst_india/report/summary_of_itc_availed/summary_of_itc_availed.py:278-281
Timestamp: 2025-06-25T08:19:02.607Z
Learning: In the Summary of ITC Availed report (india_compliance/gst_india/report/summary_of_itc_availed/summary_of_itc_availed.py), the summary dictionaries created by get_initial_summary() are never empty - they always contain tax field keys (igst_amount, cgst_amount, sgst_amount, cess_amount) with 0 values, so checking for empty dictionaries is unnecessary.

Applied to files:

  • india_compliance/gst_india/utils/e_invoice.py
🧬 Code graph analysis (1)
india_compliance/gst_india/utils/e_invoice.py (1)
india_compliance/gst_india/utils/transaction_data.py (1)
  • rounded (562-563)
⏰ 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). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Python Unit Tests
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (1)
india_compliance/gst_india/utils/e_invoice.py (1)

687-688: LGTM! Precision fix for RCM invoices.

The change correctly applies rounding to 2 decimals and absolute value for total_value in reverse charge scenarios, aligning with GST API requirements (regex pattern ^\d+\.?\d{0,2}$). This addresses the RCM Credit Note e-invoice generation error mentioned in the PR objectives.


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 requested a review from karm1000 October 27, 2025 06:29
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.59%. Comparing base (6965ff1) to head (c0b3916).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
india_compliance/gst_india/utils/e_invoice.py 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3755   +/-   ##
========================================
  Coverage    69.59%   69.59%           
========================================
  Files          182      182           
  Lines        17967    17967           
========================================
  Hits         12504    12504           
  Misses        5463     5463           
Files with missing lines Coverage Δ
india_compliance/gst_india/utils/e_invoice.py 79.71% <0.00%> (ø)

Impacted file tree graph

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

@ljain112 ljain112 merged commit 0bd1c3b into develop Oct 31, 2025
16 checks passed
@ljain112 ljain112 deleted the fix-total-item-rcm branch October 31, 2025 04:03
mergify bot added a commit that referenced this pull request Oct 31, 2025
…tfix/pr-3755

fix: absolute item total value for rcm invoice (backport #3755)
mergify bot added a commit that referenced this pull request Oct 31, 2025
…tfix/pr-3755

fix: absolute item total value for rcm invoice (backport #3755)
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.

3 participants