mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-24 21:52:21 +01:00
fix: fix restore asset value after depreciation
(cherry picked from commit 43a3400221)
This commit is contained in:
@@ -302,9 +302,18 @@ def reverse_depreciation_entry_made_after_disposal(asset, date):
|
|||||||
frappe.flags.is_reverse_depr_entry = False
|
frappe.flags.is_reverse_depr_entry = False
|
||||||
asset.flags.ignore_validate_update_after_submit = True
|
asset.flags.ignore_validate_update_after_submit = True
|
||||||
schedule.journal_entry = None
|
schedule.journal_entry = None
|
||||||
|
depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
|
||||||
|
asset.finance_books[0].value_after_depreciation += depreciation_amount
|
||||||
asset.save()
|
asset.save()
|
||||||
|
|
||||||
|
|
||||||
|
def get_depreciation_amount_in_je(journal_entry):
|
||||||
|
if journal_entry.accounts[0].debit_in_account_currency:
|
||||||
|
return journal_entry.accounts[0].debit_in_account_currency
|
||||||
|
else:
|
||||||
|
return journal_entry.accounts[0].credit_in_account_currency
|
||||||
|
|
||||||
|
|
||||||
# if the invoice had been posted on the date the depreciation was initially supposed to happen, the depreciation shouldn't be undone
|
# if the invoice had been posted on the date the depreciation was initially supposed to happen, the depreciation shouldn't be undone
|
||||||
def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_date_of_disposal):
|
def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_date_of_disposal):
|
||||||
for finance_book in asset.get("finance_books"):
|
for finance_book in asset.get("finance_books"):
|
||||||
|
|||||||
@@ -201,17 +201,29 @@ class TestAsset(AssetSetup):
|
|||||||
)
|
)
|
||||||
|
|
||||||
post_depreciation_entries(date=add_months(purchase_date, 2))
|
post_depreciation_entries(date=add_months(purchase_date, 2))
|
||||||
|
asset.load_from_db()
|
||||||
|
|
||||||
|
accumulated_depr_amount = flt(
|
||||||
|
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
||||||
|
asset.precision("gross_purchase_amount"),
|
||||||
|
)
|
||||||
|
self.assertEquals(accumulated_depr_amount, 18000.0)
|
||||||
|
|
||||||
scrap_asset(asset.name)
|
scrap_asset(asset.name)
|
||||||
|
|
||||||
asset.load_from_db()
|
asset.load_from_db()
|
||||||
self.assertEqual(asset.status, "Scrapped")
|
|
||||||
self.assertTrue(asset.journal_entry_for_scrap)
|
|
||||||
|
|
||||||
|
accumulated_depr_amount = flt(
|
||||||
|
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
||||||
|
asset.precision("gross_purchase_amount"),
|
||||||
|
)
|
||||||
pro_rata_amount, _, _ = asset.get_pro_rata_amt(
|
pro_rata_amount, _, _ = asset.get_pro_rata_amt(
|
||||||
asset.finance_books[0], 9000, add_months(get_last_day(purchase_date), 1), date
|
asset.finance_books[0], 9000, add_months(get_last_day(purchase_date), 1), date
|
||||||
)
|
)
|
||||||
pro_rata_amount = flt(pro_rata_amount, asset.precision("gross_purchase_amount"))
|
pro_rata_amount = flt(pro_rata_amount, asset.precision("gross_purchase_amount"))
|
||||||
|
self.assertEquals(accumulated_depr_amount, 18000.00 + pro_rata_amount)
|
||||||
|
|
||||||
|
self.assertEqual(asset.status, "Scrapped")
|
||||||
|
self.assertTrue(asset.journal_entry_for_scrap)
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 18000.0 + pro_rata_amount, 0.0),
|
("_Test Accumulated Depreciations - _TC", 18000.0 + pro_rata_amount, 0.0),
|
||||||
@@ -233,6 +245,12 @@ class TestAsset(AssetSetup):
|
|||||||
self.assertFalse(asset.journal_entry_for_scrap)
|
self.assertFalse(asset.journal_entry_for_scrap)
|
||||||
self.assertEqual(asset.status, "Partially Depreciated")
|
self.assertEqual(asset.status, "Partially Depreciated")
|
||||||
|
|
||||||
|
accumulated_depr_amount = flt(
|
||||||
|
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
||||||
|
asset.precision("gross_purchase_amount"),
|
||||||
|
)
|
||||||
|
self.assertEquals(accumulated_depr_amount, 18000.0)
|
||||||
|
|
||||||
def test_gle_made_by_asset_sale(self):
|
def test_gle_made_by_asset_sale(self):
|
||||||
date = nowdate()
|
date = nowdate()
|
||||||
purchase_date = add_months(get_first_day(date), -2)
|
purchase_date = add_months(get_first_day(date), -2)
|
||||||
|
|||||||
Reference in New Issue
Block a user