Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clear Depreciation Schedule before modification #28507

Merged
merged 11 commits into from
Dec 13, 2021

Conversation

GangaManoj
Copy link
Contributor

@GangaManoj GangaManoj commented Nov 22, 2021

Problem

Before performing actions that modify the Depreciation Schedule of an Asset (eg: repairs, sales, etc), the Schedule needs to be cleared of all rows that don't have Journal Entries linked with them. This is performed by clear_depreciation_schedule(). However, the function is flawed while dealing with multiple Finance Books, posing two problems:

  1. During Asset creation, if there are multiple Finance Books, it clears the Depreciation Schedule created by the first when the second is set up.
  2. While clearing the Depreciation Schedule before modification, it clears the table at the point where it encounters the first Depreciation Schedule row that isn't linked with a Journal Entry. This means that even if the Depreciation Schedule rows associated with the second Finance Book are linked with Journal Entries, they'd still get cleared.

Fix

Only clear the Depreciation Schedule rows which are not linked with Journal Entries.

Note: In each of these cases, there's an additional flaw- there's only one Depreciation Schedule entry made for the sale, even when there are multiple Finance Books. I'll fix that in a later PR.

Case 1

There are multiple Finance Books, but at the time of sale, none of the Depreciation Schedule rows are linked with Journal Entries.

Before:

Screenshot 2021-11-22 at 9 40 59 PM

After:

Screenshot 2021-11-22 at 9 41 26 PM

Case 2

There are multiple Finance Books and at the time of sale, only one of the Depreciation Schedule rows associated with each Finance Book is linked with a Journal Entry.

Before:

Screenshot 2021-11-22 at 9 44 58 PM

After:

Screenshot 2021-11-22 at 9 45 11 PM

Case 3

There are two Finance Books, and at the time of sale, all of the Depreciation Schedule rows associated with the second Finance Book are linked with Journal Entries, and all but the last Depreciation Schedule row associated with the first Finance Book are linked with Journal Entries.

Before:

Screenshot 2021-11-22 at 9 46 50 PM

After:

Screenshot 2021-11-22 at 9 47 09 PM

Testing Info
  1. Create and Submit a depreciable Asset with multiple Finance Books.
  2. Confirm that Depreciation Schedules are created for both Finance Books.
  3. Sell the Asset.
  4. Confirm that all the rows that weren't linked with Journal Entries have been cleared and that an extra entry was created on the date of sale.

(Refer Cases 1, 2 and 3 for images)

@nextchamp-saqib nextchamp-saqib added the needs-tests This PR needs automated unit-tests. label Nov 23, 2021
@GangaManoj GangaManoj removed the needs-tests This PR needs automated unit-tests. label Nov 23, 2021
@codecov
Copy link

codecov bot commented Nov 25, 2021

Codecov Report

Merging #28507 (539cba1) into develop (96a019e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop   #28507   +/-   ##
========================================
  Coverage    55.22%   55.22%           
========================================
  Files         1122     1122           
  Lines        66782    66794   +12     
========================================
+ Hits         36879    36889   +10     
- Misses       29903    29905    +2     
Impacted Files Coverage Δ
erpnext/assets/doctype/asset/asset.py 75.00% <100.00%> (+0.60%) ⬆️
...wise_balance_history/batch_wise_balance_history.py 68.96% <0.00%> (-22.42%) ⬇️
...payroll/doctype/income_tax_slab/income_tax_slab.py 83.33% <0.00%> (-16.67%) ⬇️
...e/asset_value_adjustment/asset_value_adjustment.py 86.04% <0.00%> (-3.49%) ⬇️
erpnext/education/doctype/student/student.py 73.68% <0.00%> (-3.16%) ⬇️
...value/warehouse_wise_item_balance_age_and_value.py 92.40% <0.00%> (-2.54%) ⬇️
...ion/doctype/course_enrollment/course_enrollment.py 44.00% <0.00%> (-2.00%) ⬇️
...ctype/accounting_dimension/accounting_dimension.py 64.06% <0.00%> (-1.57%) ⬇️
...e/period_closing_voucher/period_closing_voucher.py 88.23% <0.00%> (-1.48%) ⬇️
erpnext/portal/utils.py 28.98% <0.00%> (-1.45%) ⬇️
... and 16 more

@nextchamp-saqib nextchamp-saqib merged commit ce80585 into frappe:develop Dec 13, 2021
nextchamp-saqib added a commit that referenced this pull request Jan 21, 2022
…-28507

fix: Clear Depreciation Schedule before modification (backport #28507)
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.

None yet

3 participants