From a50ecffb6917ed992771bc3fabcba8b62d6fab6b Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Wed, 1 Dec 2021 21:46:09 +0530 Subject: [PATCH 1/8] fix: Fix depreciation_amount calculation (cherry picked from commit 22cc8d22462d50ef134651e7df2c36564fb7edf6) # Conflicts: # erpnext/regional/india/utils.py --- erpnext/regional/india/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index d47242e2f98..19d0781f5df 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -838,12 +838,16 @@ def update_taxable_values(doc, method): doc.get('items')[item_count - 1].taxable_value += diff def get_depreciation_amount(asset, depreciable_value, row): - depreciation_left = flt(row.total_number_of_depreciations) - flt(asset.number_of_depreciations_booked) + depreciation_left = flt(row.total_number_of_depreciations) if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: +<<<<<<< HEAD depreciation_amount = (flt(row.value_after_depreciation) - +======= + depreciation_amount = (flt(asset.gross_purchase_amount) - +>>>>>>> 22cc8d2246 (fix: Fix depreciation_amount calculation) flt(row.expected_value_after_useful_life)) / depreciation_left # if the Depreciation Schedule is being modified after Asset Repair From 7790c3267666d41302d97e7616827aa31548cab2 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Wed, 1 Dec 2021 21:48:47 +0530 Subject: [PATCH 2/8] fix: Create Depreciation Schedules properly for existing Assets (cherry picked from commit 5c3d4caedacbdfc48256a8554c7747a753ace7e2) # Conflicts: # erpnext/assets/doctype/asset/asset.py --- erpnext/assets/doctype/asset/asset.py | 39 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 03824f7b64f..b2a9890b967 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -193,8 +193,7 @@ class Asset(AccountsController): # value_after_depreciation - current Asset value if self.docstatus == 1 and d.value_after_depreciation: - value_after_depreciation = (flt(d.value_after_depreciation) - - flt(self.opening_accumulated_depreciation)) + value_after_depreciation = flt(d.value_after_depreciation) else: value_after_depreciation = (flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)) @@ -240,7 +239,7 @@ class Asset(AccountsController): break # For first row - if has_pro_rata and n==0: + if has_pro_rata and not self.opening_accumulated_depreciation and n==0: depreciation_amount, days, months = self.get_pro_rata_amt(d, depreciation_amount, self.available_for_use_date, d.depreciation_start_date) @@ -253,7 +252,7 @@ class Asset(AccountsController): if not self.flags.increase_in_asset_life: # In case of increase_in_asset_life, the self.to_date is already set on asset_repair submission self.to_date = add_months(self.available_for_use_date, - n * cint(d.frequency_of_depreciation)) + (n + self.number_of_depreciations_booked) * cint(d.frequency_of_depreciation)) depreciation_amount, days, months = self.get_pro_rata_amt(d, depreciation_amount, schedule_date, self.to_date) @@ -395,7 +394,33 @@ class Asset(AccountsController): frappe.throw(_("Depreciation Row {0}: Next Depreciation Date cannot be before Available-for-use Date") .format(row.idx)) +<<<<<<< HEAD def set_accumulated_depreciation(self, date_of_sale=None, ignore_booked_entry = False): +======= + # to ensure that final accumulated depreciation amount is accurate + def get_adjusted_depreciation_amount(self, depreciation_amount_without_pro_rata, depreciation_amount_for_last_row, finance_book): + if not self.opening_accumulated_depreciation: + depreciation_amount_for_first_row = self.get_depreciation_amount_for_first_row(finance_book) + + if depreciation_amount_for_first_row + depreciation_amount_for_last_row != depreciation_amount_without_pro_rata: + depreciation_amount_for_last_row = depreciation_amount_without_pro_rata - depreciation_amount_for_first_row + + return depreciation_amount_for_last_row + + def get_depreciation_amount_for_first_row(self, finance_book): + if self.has_only_one_finance_book(): + return self.schedules[0].depreciation_amount + else: + for schedule in self.schedules: + if schedule.finance_book == finance_book: + return schedule.depreciation_amount + + def has_only_one_finance_book(self): + if len(self.finance_books) == 1: + return True + + def set_accumulated_depreciation(self, date_of_sale=None, date_of_return=None, ignore_booked_entry = False): +>>>>>>> 5c3d4caeda (fix: Create Depreciation Schedules properly for existing Assets) straight_line_idx = [d.idx for d in self.get("schedules") if d.depreciation_method == 'Straight Line'] finance_books = [] @@ -826,12 +851,16 @@ def get_total_days(date, frequency): @erpnext.allow_regional def get_depreciation_amount(asset, depreciable_value, row): - depreciation_left = flt(row.total_number_of_depreciations) - flt(asset.number_of_depreciations_booked) + depreciation_left = flt(row.total_number_of_depreciations) if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: +<<<<<<< HEAD depreciation_amount = (flt(row.value_after_depreciation) - +======= + depreciation_amount = (flt(asset.gross_purchase_amount) - +>>>>>>> 5c3d4caeda (fix: Create Depreciation Schedules properly for existing Assets) flt(row.expected_value_after_useful_life)) / depreciation_left # if the Depreciation Schedule is being modified after Asset Repair From c888904cd2d840482319d11a1a73791fe0689b55 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Wed, 1 Dec 2021 22:04:56 +0530 Subject: [PATCH 3/8] fix: Modify has_pro_rata() to include existing assets (cherry picked from commit de002005acc509d025b642b8de0823b2e807f11e) --- erpnext/assets/doctype/asset/asset.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index b2a9890b967..cb5a2541654 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -348,7 +348,12 @@ class Asset(AccountsController): # if it returns True, depreciation_amount will not be equal for the first and last rows def check_is_pro_rata(self, row): has_pro_rata = False - days = date_diff(row.depreciation_start_date, self.available_for_use_date) + 1 + + # if not existing asset, from_date = available_for_use_date + # otherwise, if number_of_depreciations_booked = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12 + # from_date = 01/01/2022 + from_date = self.get_modified_available_for_use_date(row) + days = date_diff(row.depreciation_start_date, from_date) + 1 # if frequency_of_depreciation is 12 months, total_days = 365 total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation) @@ -358,6 +363,9 @@ class Asset(AccountsController): return has_pro_rata + def get_modified_available_for_use_date(self, row): + return add_months(self.available_for_use_date, (self.number_of_depreciations_booked * row.frequency_of_depreciation)) + def validate_asset_finance_books(self, row): if flt(row.expected_value_after_useful_life) >= flt(self.gross_purchase_amount): frappe.throw(_("Row {0}: Expected Value After Useful Life must be less than Gross Purchase Amount") From a12000921f483a48022e589b3f1bf2963c0579d5 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Wed, 1 Dec 2021 22:51:55 +0530 Subject: [PATCH 4/8] fix: Test if depreciation schedules are set up properly for existing assets (cherry picked from commit 774ac852c95d2a63ef5cde24e46c9f0fece36505) # Conflicts: # erpnext/assets/doctype/asset/test_asset.py --- erpnext/assets/doctype/asset/test_asset.py | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 0b5e41ee7ef..54fbf109e57 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -635,6 +635,184 @@ class TestAsset(unittest.TestCase): frappe.db.set_value("Asset Category Account", name, "capital_work_in_progress_account", cwip_acc) frappe.db.get_value("Company", "_Test Company", "capital_work_in_progress_account", cwip_acc) +<<<<<<< HEAD +======= +class TestDepreciationMethods(AssetSetup): + def test_schedule_for_straight_line_method(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-01-01", + purchase_date = "2030-01-01", + expected_value_after_useful_life = 10000, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.status, "Draft") + expected_schedules = [ + ["2030-12-31", 30000.00, 30000.00], + ["2031-12-31", 30000.00, 60000.00], + ["2032-12-31", 30000.00, 90000.00] + ] + + schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + def test_schedule_for_straight_line_method_for_existing_asset(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-06-06", + is_existing_asset = 1, + number_of_depreciations_booked = 2, + opening_accumulated_depreciation = 47095.89, + expected_value_after_useful_life = 10000, + depreciation_start_date = "2032-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.status, "Draft") + expected_schedules = [ + ["2032-12-31", 30000.0, 77095.89], + ["2033-06-06", 12904.11, 90000.0] + ] + schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + def test_schedule_for_double_declining_method(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-01-01", + purchase_date = "2030-01-01", + depreciation_method = "Double Declining Balance", + expected_value_after_useful_life = 10000, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.status, "Draft") + + expected_schedules = [ + ['2030-12-31', 66667.00, 66667.00], + ['2031-12-31', 22222.11, 88889.11], + ['2032-12-31', 1110.89, 90000.0] + ] + + schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + def test_schedule_for_double_declining_method_for_existing_asset(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-01-01", + is_existing_asset = 1, + depreciation_method = "Double Declining Balance", + number_of_depreciations_booked = 1, + opening_accumulated_depreciation = 50000, + expected_value_after_useful_life = 10000, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.status, "Draft") + + expected_schedules = [ + ["2030-12-31", 33333.50, 83333.50], + ["2031-12-31", 6666.50, 90000.0] + ] + + schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + def test_schedule_for_prorated_straight_line_method(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-01-30", + purchase_date = "2030-01-30", + depreciation_method = "Straight Line", + expected_value_after_useful_life = 10000, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + expected_schedules = [ + ["2030-12-31", 27534.25, 27534.25], + ["2031-12-31", 30000.0, 57534.25], + ["2032-12-31", 30000.0, 87534.25], + ["2033-01-30", 2465.75, 90000.0] + ] + + schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + # WDV: Written Down Value method + def test_depreciation_entry_for_wdv_without_pro_rata(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-01-01", + purchase_date = "2030-01-01", + depreciation_method = "Written Down Value", + expected_value_after_useful_life = 12500, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) + + expected_schedules = [ + ["2030-12-31", 50000.0, 50000.0], + ["2031-12-31", 25000.0, 75000.0], + ["2032-12-31", 12500.0, 87500.0], + ] + + schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + + # WDV: Written Down Value method + def test_pro_rata_depreciation_entry_for_wdv(self): + asset = create_asset( + calculate_depreciation = 1, + available_for_use_date = "2030-06-06", + purchase_date = "2030-01-01", + depreciation_method = "Written Down Value", + expected_value_after_useful_life = 12500, + depreciation_start_date = "2030-12-31", + total_number_of_depreciations = 3, + frequency_of_depreciation = 12 + ) + + self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) + + expected_schedules = [ + ["2030-12-31", 28493.15, 28493.15], + ["2031-12-31", 35753.43, 64246.58], + ["2032-12-31", 17876.71, 82123.29], + ["2033-06-06", 5376.71, 87500.0] + ] + + schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] + for d in asset.get("schedules")] + + self.assertEqual(schedules, expected_schedules) + +>>>>>>> 774ac852c9 (fix: Test if depreciation schedules are set up properly for existing assets) def test_discounted_wdv_depreciation_rate_for_indian_region(self): # set indian company company_flag = frappe.flags.company From e5a5d5f8e5f142c1ab9d6b2a7021a7d7a9c93448 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Thu, 2 Dec 2021 01:09:15 +0530 Subject: [PATCH 5/8] fix: Remove unnecessary variable (cherry picked from commit 828769ca707460c5f04ddf8a5900b57188d0856f) # Conflicts: # erpnext/assets/doctype/asset/asset.py # erpnext/regional/india/utils.py --- erpnext/assets/doctype/asset/asset.py | 6 ++++-- erpnext/regional/india/utils.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index cb5a2541654..0b6cdd5e442 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -859,8 +859,6 @@ def get_total_days(date, frequency): @erpnext.allow_regional def get_depreciation_amount(asset, depreciable_value, row): - depreciation_left = flt(row.total_number_of_depreciations) - if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: @@ -868,8 +866,12 @@ def get_depreciation_amount(asset, depreciable_value, row): depreciation_amount = (flt(row.value_after_depreciation) - ======= depreciation_amount = (flt(asset.gross_purchase_amount) - +<<<<<<< HEAD >>>>>>> 5c3d4caeda (fix: Create Depreciation Schedules properly for existing Assets) flt(row.expected_value_after_useful_life)) / depreciation_left +======= + flt(row.expected_value_after_useful_life)) / flt(row.total_number_of_depreciations) +>>>>>>> 828769ca70 (fix: Remove unnecessary variable) # if the Depreciation Schedule is being modified after Asset Repair else: diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 19d0781f5df..a6a48b1e9cf 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -838,8 +838,6 @@ def update_taxable_values(doc, method): doc.get('items')[item_count - 1].taxable_value += diff def get_depreciation_amount(asset, depreciable_value, row): - depreciation_left = flt(row.total_number_of_depreciations) - if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: @@ -847,8 +845,12 @@ def get_depreciation_amount(asset, depreciable_value, row): depreciation_amount = (flt(row.value_after_depreciation) - ======= depreciation_amount = (flt(asset.gross_purchase_amount) - +<<<<<<< HEAD >>>>>>> 22cc8d2246 (fix: Fix depreciation_amount calculation) flt(row.expected_value_after_useful_life)) / depreciation_left +======= + flt(row.expected_value_after_useful_life)) / flt(row.total_number_of_depreciations) +>>>>>>> 828769ca70 (fix: Remove unnecessary variable) # if the Depreciation Schedule is being modified after Asset Repair else: From ae330bc132ef1fe20472b88b5d64b9763b5fa61b Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Fri, 3 Dec 2021 11:44:06 +0530 Subject: [PATCH 6/8] fix: conflicts --- erpnext/assets/doctype/asset/asset.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 0b6cdd5e442..b1658a0c211 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -402,9 +402,6 @@ class Asset(AccountsController): frappe.throw(_("Depreciation Row {0}: Next Depreciation Date cannot be before Available-for-use Date") .format(row.idx)) -<<<<<<< HEAD - def set_accumulated_depreciation(self, date_of_sale=None, ignore_booked_entry = False): -======= # to ensure that final accumulated depreciation amount is accurate def get_adjusted_depreciation_amount(self, depreciation_amount_without_pro_rata, depreciation_amount_for_last_row, finance_book): if not self.opening_accumulated_depreciation: @@ -427,8 +424,7 @@ class Asset(AccountsController): if len(self.finance_books) == 1: return True - def set_accumulated_depreciation(self, date_of_sale=None, date_of_return=None, ignore_booked_entry = False): ->>>>>>> 5c3d4caeda (fix: Create Depreciation Schedules properly for existing Assets) + def set_accumulated_depreciation(self, date_of_sale=None, ignore_booked_entry = False): straight_line_idx = [d.idx for d in self.get("schedules") if d.depreciation_method == 'Straight Line'] finance_books = [] @@ -862,16 +858,8 @@ def get_depreciation_amount(asset, depreciable_value, row): if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: -<<<<<<< HEAD - depreciation_amount = (flt(row.value_after_depreciation) - -======= depreciation_amount = (flt(asset.gross_purchase_amount) - -<<<<<<< HEAD ->>>>>>> 5c3d4caeda (fix: Create Depreciation Schedules properly for existing Assets) - flt(row.expected_value_after_useful_life)) / depreciation_left -======= flt(row.expected_value_after_useful_life)) / flt(row.total_number_of_depreciations) ->>>>>>> 828769ca70 (fix: Remove unnecessary variable) # if the Depreciation Schedule is being modified after Asset Repair else: From bcb372ab6160cb4741474a00fe0a74a9509a99c4 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Fri, 3 Dec 2021 11:46:50 +0530 Subject: [PATCH 7/8] fix: conflicts --- erpnext/assets/doctype/asset/test_asset.py | 178 --------------------- erpnext/regional/india/utils.py | 8 - 2 files changed, 186 deletions(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 54fbf109e57..0b5e41ee7ef 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -635,184 +635,6 @@ class TestAsset(unittest.TestCase): frappe.db.set_value("Asset Category Account", name, "capital_work_in_progress_account", cwip_acc) frappe.db.get_value("Company", "_Test Company", "capital_work_in_progress_account", cwip_acc) -<<<<<<< HEAD -======= -class TestDepreciationMethods(AssetSetup): - def test_schedule_for_straight_line_method(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-01-01", - purchase_date = "2030-01-01", - expected_value_after_useful_life = 10000, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.status, "Draft") - expected_schedules = [ - ["2030-12-31", 30000.00, 30000.00], - ["2031-12-31", 30000.00, 60000.00], - ["2032-12-31", 30000.00, 90000.00] - ] - - schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - def test_schedule_for_straight_line_method_for_existing_asset(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-06-06", - is_existing_asset = 1, - number_of_depreciations_booked = 2, - opening_accumulated_depreciation = 47095.89, - expected_value_after_useful_life = 10000, - depreciation_start_date = "2032-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.status, "Draft") - expected_schedules = [ - ["2032-12-31", 30000.0, 77095.89], - ["2033-06-06", 12904.11, 90000.0] - ] - schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - def test_schedule_for_double_declining_method(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-01-01", - purchase_date = "2030-01-01", - depreciation_method = "Double Declining Balance", - expected_value_after_useful_life = 10000, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.status, "Draft") - - expected_schedules = [ - ['2030-12-31', 66667.00, 66667.00], - ['2031-12-31', 22222.11, 88889.11], - ['2032-12-31', 1110.89, 90000.0] - ] - - schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - def test_schedule_for_double_declining_method_for_existing_asset(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-01-01", - is_existing_asset = 1, - depreciation_method = "Double Declining Balance", - number_of_depreciations_booked = 1, - opening_accumulated_depreciation = 50000, - expected_value_after_useful_life = 10000, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.status, "Draft") - - expected_schedules = [ - ["2030-12-31", 33333.50, 83333.50], - ["2031-12-31", 6666.50, 90000.0] - ] - - schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - def test_schedule_for_prorated_straight_line_method(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-01-30", - purchase_date = "2030-01-30", - depreciation_method = "Straight Line", - expected_value_after_useful_life = 10000, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - expected_schedules = [ - ["2030-12-31", 27534.25, 27534.25], - ["2031-12-31", 30000.0, 57534.25], - ["2032-12-31", 30000.0, 87534.25], - ["2033-01-30", 2465.75, 90000.0] - ] - - schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - # WDV: Written Down Value method - def test_depreciation_entry_for_wdv_without_pro_rata(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-01-01", - purchase_date = "2030-01-01", - depreciation_method = "Written Down Value", - expected_value_after_useful_life = 12500, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) - - expected_schedules = [ - ["2030-12-31", 50000.0, 50000.0], - ["2031-12-31", 25000.0, 75000.0], - ["2032-12-31", 12500.0, 87500.0], - ] - - schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - - # WDV: Written Down Value method - def test_pro_rata_depreciation_entry_for_wdv(self): - asset = create_asset( - calculate_depreciation = 1, - available_for_use_date = "2030-06-06", - purchase_date = "2030-01-01", - depreciation_method = "Written Down Value", - expected_value_after_useful_life = 12500, - depreciation_start_date = "2030-12-31", - total_number_of_depreciations = 3, - frequency_of_depreciation = 12 - ) - - self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) - - expected_schedules = [ - ["2030-12-31", 28493.15, 28493.15], - ["2031-12-31", 35753.43, 64246.58], - ["2032-12-31", 17876.71, 82123.29], - ["2033-06-06", 5376.71, 87500.0] - ] - - schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] - for d in asset.get("schedules")] - - self.assertEqual(schedules, expected_schedules) - ->>>>>>> 774ac852c9 (fix: Test if depreciation schedules are set up properly for existing assets) def test_discounted_wdv_depreciation_rate_for_indian_region(self): # set indian company company_flag = frappe.flags.company diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index a6a48b1e9cf..fe71053e5cb 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -841,16 +841,8 @@ def get_depreciation_amount(asset, depreciable_value, row): if row.depreciation_method in ("Straight Line", "Manual"): # if the Depreciation Schedule is being prepared for the first time if not asset.flags.increase_in_asset_life: -<<<<<<< HEAD - depreciation_amount = (flt(row.value_after_depreciation) - -======= depreciation_amount = (flt(asset.gross_purchase_amount) - -<<<<<<< HEAD ->>>>>>> 22cc8d2246 (fix: Fix depreciation_amount calculation) - flt(row.expected_value_after_useful_life)) / depreciation_left -======= flt(row.expected_value_after_useful_life)) / flt(row.total_number_of_depreciations) ->>>>>>> 828769ca70 (fix: Remove unnecessary variable) # if the Depreciation Schedule is being modified after Asset Repair else: From a9bcc869b95c97c6b22411fe99ac2d5473d8613c Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Mon, 6 Dec 2021 16:12:18 +0530 Subject: [PATCH 8/8] fix: conflicts --- erpnext/assets/doctype/asset/test_asset.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 151a8a47d93..74def67f836 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -409,19 +409,18 @@ class TestDepreciationMethods(AssetSetup): calculate_depreciation = 1, available_for_use_date = "2030-06-06", is_existing_asset = 1, - number_of_depreciations_booked = 1, - opening_accumulated_depreciation = 40000, + number_of_depreciations_booked = 2, + opening_accumulated_depreciation = 47095.89, expected_value_after_useful_life = 10000, - depreciation_start_date = "2030-12-31", + depreciation_start_date = "2032-12-31", total_number_of_depreciations = 3, frequency_of_depreciation = 12 ) self.assertEqual(asset.status, "Draft") expected_schedules = [ - ["2030-12-31", 14246.58, 54246.58], - ["2031-12-31", 25000.00, 79246.58], - ["2032-06-06", 10753.42, 90000.00] + ["2032-12-31", 30000.0, 77095.89], + ["2033-06-06", 12904.11, 90000.0] ] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] for d in asset.get("schedules")]