[master] [All-e]Fixed asset report 5607 and 4413 showing different results with Declining Balance#8324
Conversation
…-5607-and-4413-showing-different-results
…g-different-results' of https://github.com/neeleshsinghal/BCApps into bugs/Bug-636727-Fixed-asset-report-5607-and-4413-showing-different-results
…-5607-and-4413-showing-different-results
AleksanderGladkov
left a comment
There was a problem hiding this comment.
@neeleshsinghal please also add description to the PR
|
|
||
| // [GIVEN] Create Accounting periods with fiscal year. | ||
| CleanupFixedAssetData(); | ||
| AccountingPeriod.DeleteAll(); |
There was a problem hiding this comment.
AccountingPeriod.DeleteAll() affects global test state
AccountingPeriod.DeleteAll() removes every accounting period from the database at the start of the test. Other tests that expect accounting periods to exist and run concurrently (or after, if a Commit() persists this) may fail or produce wrong results.
Recommendation:
- Restrict the deletion to only the periods created by this test, or call
DeleteAll()only on a filtered record set. Also ensure cleanup is mirrored in aTearDownor within the same transaction boundary.
| AccountingPeriod.DeleteAll(); | |
| // Filter to only the fiscal year range created for this test: | |
| AccountingPeriod.SetRange("Starting Date", CalcDate('<-1Y>', FiscalYearStartDate), | |
| CalcDate('<' + Format(NumberOfMonths) + 'M>', FiscalYearStartDate)); | |
| AccountingPeriod.DeleteAll(); |
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why
|
|
||
| // The next projected month should be based on this closing book value. | ||
| ExpectedProjectedDepr := -Round(BookValueAfterDepr * DecliningBalancePct / 100 / 12, 1); | ||
| Commit(); |
There was a problem hiding this comment.
Commit() in test breaks isolation
Calling Commit() inside a test procedure persists all changes to the database, bypassing the automatic transaction rollback that test isolation relies on. If a subsequent assertion fails, the FA journal entries, fixed asset, and accounting periods created in the test will remain in the database and can pollute other tests.
Recommendation:
- Refactor the test to avoid
Commit(). If the report runner requires committed data, use a[TransactionModel(TransactionModel::AutoCommit)]attribute or restructure the setup so committed data is cleaned up in aTearDownprocedure.
| Commit(); | |
| // Replace the bare Commit() with explicit cleanup or use TransactionModel: | |
| [Test] | |
| [TransactionModel(TransactionModel::AutoCommit)] | |
| [HandlerFunctions('EXRFixedAssetProjectedHandler')] | |
| procedure ProjectedValueDeclBalShouldUseCorrectBookValueAcrossFiscalYear() |
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why
| BasePostingDate: Date; | ||
| DeprStartDate: Date; | ||
| FirstReportDeprDate: Date; | ||
| FiscalYearStartDate: Date; |
There was a problem hiding this comment.
AccountingPeriod.DeleteAll() pollutes test data
AccountingPeriod.DeleteAll() is called inside the test body without being wrapped in a LibrarySetupStorage.Save/Restore or equivalent cleanup. If the test fails mid-way, or if other tests running in the same session rely on existing accounting periods, the global table state is permanently corrupted for that test run.
Recommendation:
- Move accounting-period setup and teardown into the
Initialize/ cleanup helpers, or useLibraryFiscalYearto ensure periods are restored after the test. At minimum, addAccountingPeriod.DeleteAll()toCleanupFixedAssetDatawith anif IsInitializedguard.
| FiscalYearStartDate: Date; | |
| // In CleanupFixedAssetData or a dedicated TearDown: | |
| AccountingPeriod.DeleteAll(); | |
| LibraryFiscalYear.CreateFiscalYear(); |
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why
| end; | ||
|
|
||
| [RequestPageHandler] | ||
| procedure EXRFixedAssetProjectedHandler(var EXRFixedAssetProjected: TestRequestPage "EXR Fixed Asset Projected") |
There was a problem hiding this comment.
Missing newline at end of file
The diff shows \ No newline at end of file for FixedAssetExcelReports.Codeunit.al. AL source files should end with a trailing newline for consistent diff output and to avoid spurious whitespace changes in future edits.
Recommendation:
- Add a single newline character after the closing
}of the codeunit.
| procedure EXRFixedAssetProjectedHandler(var EXRFixedAssetProjected: TestRequestPage "EXR Fixed Asset Projected") | |
| } |
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why
|
Workitem :
Bug 636727: [master] [All-e]Fixed asset report 5607 and 4413 showing different results with Declining Balance
Fixes AB#636727
Issue: Report 4413 (Fixed Asset Projected Value Excel) calculates incorrect depreciation amounts for Declining Balance assets when projections cross a fiscal year boundary, producing different results than the legacy Report 5607.
Cause: In InsertProjectedEntries, EntryAmounts[3] (depreciation in fiscal year) was reset to 0 before accumulating the current period's depreciation, causing the last fiscal period's depreciation to spill into the new fiscal year and shifting the effective book value base back one month.
Solution: Moved AccumulateProjectionEntryAmounts before the fiscal year boundary reset (EntryAmounts[3] := 0) so the outgoing fiscal year's final depreciation is fully accumulated before the counter resets, matching the order used in Report 5607.