fix: update cancel_depreciation_entries logic and add test cases for asset depreciation - #4674
fix: update cancel_depreciation_entries logic and add test cases for asset depreciation#4674ljain112 wants to merge 2 commits into
Conversation
…asset depreciation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 35 |
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.
| finance_books=[ | ||
| {"finance_book": self.fb_regular.name, "depreciation_start_date": "2025-03-31"}, | ||
| {"finance_book": self.fb_income_tax.name, "depreciation_start_date": "2025-03-31"}, | ||
| ], |
There was a problem hiding this comment.
Blank-row regression remains untested
This scrap fixture contains only named REGULAR and INCOME-TAX finance-book rows, so it never exercises the blank finance_book branch that the cancellation change fixes. The former early return behavior still passes this test because it reaches the Income Tax row normally. Add a blank finance-book row before the Income Tax row and retain the cancellation assertion; that fixture fails under the old behavior and verifies that processing continues after blank rows.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Artifacts
Executable cancellation-loop comparison script
- Authored Python harness that imports the repository cancellation function, restores only the old branch in a temporary file, and runs named-book and blank-row cases; it demonstrates the test distinction.
Old early-return cancellation behavior
- Captured command output for the temporary old implementation; the named-book case passes while a blank row before the income-tax row prevents cancellation, confirming the existing test would pass before the fix.
Current skip-blank-row cancellation behavior
- Captured command output for the current repository implementation; both named-book and blank-row cases cancel the income-tax journal entry, confirming the changed branch fixes the reproduced failure.
Confidence Score: 3/5Not safe to merge until T-Rex findings are addressed. The cancellation behavior handles the reproduced blank-row case, but the committed test would also pass with the previous behavior that left the later Income Tax Act depreciation entry active. T-Rex reproduced 2 failing behaviors at runtime in india_compliance/income_tax_india/overrides/test_asset_depreciation_schedule.py; the change needs fixes before it is safe to merge. Files Needing Attention: india_compliance/income_tax_india/overrides/test_asset_depreciation_schedule.py
What T-Rex did
|
📝 WalkthroughWalkthroughAdds integration coverage for Income Tax Act asset depreciation, including finance-book selection, 180-day rate rules, annual and monthly schedules, first-year treatment, leap-year proration, and disposal-year cancellation. Adds asset creation and company depreciation-setting test utilities. Updates cancellation logic to skip finance-book rows without a finance book and continue processing subsequent rows. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
india_compliance/tests/erpnext_test_utils.py (1)
366-387: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
value()can't express an explicit falsy per-row override.
row.get(fieldname) or args.get(fieldname) or defaulttreats an explicitly-set falsy row value (e.g.daily_prorata_based=0,rate_of_depreciation=0) the same as "not set", silently falling through to the top-levelargsvalue instead. This is dormant today (no current test sets a falsy row override against a truthy top-level default) but will silently produce the wrong finance-book row for the next test author who does.♻️ Suggested fix using a sentinel to distinguish "missing" from "falsy"
- def value(row, fieldname, default=None): - return row.get(fieldname) or args.get(fieldname) or default + _unset = object() + + def value(row, fieldname, default=None): + for source in (row, args): + v = source.get(fieldname, _unset) + if v is not _unset and v is not None: + return v + return defaultindia_compliance/income_tax_india/overrides/test_asset_depreciation_schedule.py (1)
371-393: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a finance-book row without a
finance_bookto actually cover the fix.Both rows here (
fb_regular,fb_income_tax) setfinance_bookexplicitly, so this test only exercises the pre-existingfb_for_income_tax_mapskip incancel_depreciation_entries(india_compliance/income_tax_india/overrides/asset_depreciation_schedule.py Lines 131-132), not thereturn→continuefix on Line 129. That fix specifically matters when a row has nofinance_book(e.g. the default company book) before an Income Tax Act row — previously that would abort the whole loop and leave the Income Tax book's disposal-year entries uncancelled.🧪 Suggested addition to pin the actual fix
def test_only_income_tax_finance_book_is_cancelled_on_scrap(self): asset = self._create_asset( "2024-04-01", finance_books=[ + # a blank finance_book row (e.g. the default company book) must not + # abort processing of the Income Tax Act row that follows it + {"depreciation_start_date": "2025-03-31"}, {"finance_book": self.fb_regular.name, "depreciation_start_date": "2025-03-31"}, {"finance_book": self.fb_income_tax.name, "depreciation_start_date": "2025-03-31"}, ], )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1d2c46c5-a85a-4c7c-ba80-4e5d4ebdbd51
📒 Files selected for processing (3)
india_compliance/income_tax_india/overrides/asset_depreciation_schedule.pyindia_compliance/income_tax_india/overrides/test_asset_depreciation_schedule.pyindia_compliance/tests/erpnext_test_utils.py
closes: #4640
Issue only if the user has upgraded from v14.
The latest version of erpnext already has validation for a mandatory finance book for more than one finance book.