diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 6d726039414e1337d43af2df3ff562d4bf132318..1e772f47d996ca048469de106f1951400754cab2 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -198,7 +198,8 @@ class JournalEntry(AccountsController): self.update_asset_value() self.update_inter_company_jv() self.update_invoice_discounting() - self.update_unreconciled_amount() + self.update_unreconciled_amount() # @dokos + self.update_booked_depreciation() def on_update_after_submit(self): if hasattr(self, "repost_required"): @@ -232,6 +233,7 @@ class JournalEntry(AccountsController): self.unlink_inter_company_jv() self.unlink_asset_adjustment_entry() self.update_invoice_discounting() + self.update_booked_depreciation() def get_title(self): return self.pay_to_recd_from or self.accounts[0].account @@ -449,6 +451,28 @@ class JournalEntry(AccountsController): if status: inv_disc_doc.set_status(status=status) + def update_booked_depreciation(self): + for d in self.get("accounts"): + if ( + self.voucher_type == "Depreciation Entry" + and d.reference_type == "Asset" + and d.reference_name + and frappe.get_cached_value("Account", d.account, "root_type") == "Expense" + and d.debit + ): + asset = frappe.get_doc("Asset", d.reference_name) + for fb_row in asset.get("finance_books"): + if fb_row.finance_book == self.finance_book: + depr_schedule = get_depr_schedule(asset.name, "Active", fb_row.finance_book) + total_number_of_booked_depreciations = asset.opening_number_of_booked_depreciations + for je in depr_schedule: + if je.journal_entry: + total_number_of_booked_depreciations += 1 + fb_row.db_set( + "total_number_of_booked_depreciations", total_number_of_booked_depreciations + ) + break + def unlink_advance_entry_reference(self): for d in self.get("accounts"): if d.is_advance == "Yes" and d.reference_type in ("Sales Invoice", "Purchase Invoice"): diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index 3a2a942bdf2bf5d010ba83998e6d8eb9e6e097ff..99a430cbb400d38be8f9d7c3d868ffc784dc8a21 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -45,7 +45,7 @@ "calculate_depreciation", "column_break_33", "opening_accumulated_depreciation", - "number_of_depreciations_booked", + "opening_number_of_booked_depreciations", "is_fully_depreciated", "section_break_36", "finance_books", @@ -257,12 +257,6 @@ "label": "Opening Accumulated Depreciation", "options": "Company:company:default_currency" }, - { - "depends_on": "eval:(doc.is_existing_asset)", - "fieldname": "number_of_depreciations_booked", - "fieldtype": "Int", - "label": "Number of Depreciations Booked" - }, { "collapsible": 1, "collapsible_depends_on": "eval:doc.calculate_depreciation || doc.is_existing_asset", @@ -546,6 +540,12 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 + }, + { + "depends_on": "eval:(doc.is_existing_asset)", + "fieldname": "opening_number_of_booked_depreciations", + "fieldtype": "Int", + "label": "Opening Number of Booked Depreciations" } ], "idx": 72, @@ -589,7 +589,7 @@ "link_fieldname": "target_asset" } ], - "modified": "2024-04-18 16:45:47.306032", + "modified": "2024-05-21 13:46:21.066483", "modified_by": "Administrator", "module": "Assets", "name": "Asset", diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 8be798612684a86a474457c9ccff698efbacc9cc..d31348d158c10e12ce5fc1e1be23963253136844 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -89,8 +89,8 @@ class Asset(AccountsController): maintenance_required: DF.Check naming_series: DF.Literal["ACC-ASS-.YYYY.-"] next_depreciation_date: DF.Date | None - number_of_depreciations_booked: DF.Int opening_accumulated_depreciation: DF.Currency + opening_number_of_booked_depreciations: DF.Int policy_number: DF.Data | None purchase_amount: DF.Currency purchase_date: DF.Date | None @@ -145,7 +145,7 @@ class Asset(AccountsController): "Asset Depreciation Schedules created:
{0}

Please check, edit if needed, and submit the Asset." ).format(asset_depr_schedules_links) ) - + self.set_total_booked_depreciations() self.total_asset_cost = self.gross_purchase_amount self.status = self.get_status() @@ -419,7 +419,7 @@ class Asset(AccountsController): if not self.is_existing_asset: self.opening_accumulated_depreciation = 0 - self.number_of_depreciations_booked = 0 + self.opening_number_of_booked_depreciations = 0 else: depreciable_amount = flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life) if flt(self.opening_accumulated_depreciation) > depreciable_amount: @@ -430,15 +430,15 @@ class Asset(AccountsController): ) if self.opening_accumulated_depreciation: - if not self.number_of_depreciations_booked: - frappe.throw(_("Please set Number of Depreciations Booked")) + if not self.opening_number_of_booked_depreciations: + frappe.throw(_("Please set Opening Number of Booked Depreciations")) else: - self.number_of_depreciations_booked = 0 + self.opening_number_of_booked_depreciations = 0 - if flt(row.total_number_of_depreciations) <= cint(self.number_of_depreciations_booked): + if flt(row.total_number_of_depreciations) <= cint(self.opening_number_of_booked_depreciations): frappe.throw( _( - "Row {0}: Total Number of Depreciations cannot be less than or equal to Number of Depreciations Booked" + "Row {0}: Total Number of Depreciations cannot be less than or equal to Opening Number of Booked Depreciations" ).format(row.idx), title=_("Invalid Schedule"), ) @@ -459,6 +459,17 @@ class Asset(AccountsController): ).format(row.idx) ) + def set_total_booked_depreciations(self): + # set value of total number of booked depreciations field + for fb_row in self.get("finance_books"): + total_number_of_booked_depreciations = self.opening_number_of_booked_depreciations + depr_schedule = get_depr_schedule(self.name, "Active", fb_row.finance_book) + if depr_schedule: + for je in depr_schedule: + if je.journal_entry: + total_number_of_booked_depreciations += 1 + fb_row.db_set("total_number_of_booked_depreciations", total_number_of_booked_depreciations) + def validate_expected_value_after_useful_life(self): for row in self.get("finance_books"): depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book) diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index dc6b16dc023eed4c5e700b7d477fb655d869479e..93f32b43b4ce34d62e7dcb68657c8cd9d4e84518 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -325,6 +325,7 @@ def _make_journal_entry_for_depreciation( if not je.meta.get_workflow(): je.submit() + asset.reload() idx = cint(asset_depr_schedule_doc.finance_book_id) row = asset.get("finance_books")[idx - 1] row.value_after_depreciation -= depr_schedule.depreciation_amount diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 8298fc003db0de9d69e400d6dc2c59c3e43853e0..a634550089f739bb76abce094683b40136da5f36 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -359,7 +359,7 @@ class TestAsset(AssetSetup): purchase_date="2020-04-01", expected_value_after_useful_life=0, total_number_of_depreciations=5, - number_of_depreciations_booked=2, + opening_number_of_booked_depreciations=2, frequency_of_depreciation=12, depreciation_start_date="2023-03-31", opening_accumulated_depreciation=24000, @@ -457,7 +457,7 @@ class TestAsset(AssetSetup): purchase_date="2020-01-01", expected_value_after_useful_life=0, total_number_of_depreciations=6, - number_of_depreciations_booked=1, + opening_number_of_booked_depreciations=1, frequency_of_depreciation=10, depreciation_start_date="2021-01-01", opening_accumulated_depreciation=20000, @@ -743,7 +743,7 @@ class TestDepreciationMethods(AssetSetup): calculate_depreciation=1, available_for_use_date="2030-06-06", is_existing_asset=1, - number_of_depreciations_booked=2, + opening_number_of_booked_depreciations=2, opening_accumulated_depreciation=47095.89, expected_value_after_useful_life=10000, depreciation_start_date="2032-12-31", @@ -793,7 +793,7 @@ class TestDepreciationMethods(AssetSetup): available_for_use_date="2030-01-01", is_existing_asset=1, depreciation_method="Double Declining Balance", - number_of_depreciations_booked=1, + opening_number_of_booked_depreciations=1, opening_accumulated_depreciation=50000, expected_value_after_useful_life=10000, depreciation_start_date="2031-12-31", @@ -1127,8 +1127,8 @@ class TestDepreciationBasics(AssetSetup): self.assertRaises(frappe.ValidationError, asset.save) - def test_number_of_depreciations_booked(self): - """Tests if an error is raised when number_of_depreciations_booked is not specified when opening_accumulated_depreciation is.""" + def test_opening_booked_depreciations(self): + """Tests if an error is raised when opening_number_of_booked_depreciations is not specified when opening_accumulated_depreciation is.""" asset = create_asset( item_code="Macbook Pro", @@ -1144,9 +1144,9 @@ class TestDepreciationBasics(AssetSetup): self.assertRaises(frappe.ValidationError, asset.save) def test_number_of_depreciations(self): - """Tests if an error is raised when number_of_depreciations_booked >= total_number_of_depreciations.""" + """Tests if an error is raised when opening_number_of_booked_depreciations >= total_number_of_depreciations.""" - # number_of_depreciations_booked > total_number_of_depreciations + # opening_number_of_booked_depreciations > total_number_of_depreciations asset = create_asset( item_code="Macbook Pro", calculate_depreciation=1, @@ -1155,13 +1155,13 @@ class TestDepreciationBasics(AssetSetup): expected_value_after_useful_life=10000, depreciation_start_date="2020-07-01", opening_accumulated_depreciation=10000, - number_of_depreciations_booked=5, + opening_number_of_booked_depreciations=5, do_not_save=1, ) self.assertRaises(frappe.ValidationError, asset.save) - # number_of_depreciations_booked = total_number_of_depreciations + # opening_number_of_booked_depreciations = total_number_of_depreciations asset_2 = create_asset( item_code="Macbook Pro", calculate_depreciation=1, @@ -1170,7 +1170,7 @@ class TestDepreciationBasics(AssetSetup): expected_value_after_useful_life=10000, depreciation_start_date="2020-07-01", opening_accumulated_depreciation=10000, - number_of_depreciations_booked=5, + opening_number_of_booked_depreciations=5, do_not_save=1, ) @@ -1506,7 +1506,7 @@ class TestDepreciationBasics(AssetSetup): asset = create_asset(calculate_depreciation=1) asset.opening_accumulated_depreciation = 2000 - asset.number_of_depreciations_booked = 1 + asset.opening_number_of_booked_depreciations = 1 asset.finance_books[0].expected_value_after_useful_life = 100 asset.save() @@ -1709,7 +1709,7 @@ def create_asset(**args): "purchase_date": args.purchase_date or "2015-01-01", "calculate_depreciation": args.calculate_depreciation or 0, "opening_accumulated_depreciation": args.opening_accumulated_depreciation or 0, - "number_of_depreciations_booked": args.number_of_depreciations_booked or 0, + "opening_number_of_booked_depreciations": args.opening_number_of_booked_depreciations or 0, "gross_purchase_amount": args.gross_purchase_amount or 100000, "purchase_amount": args.purchase_amount or 100000, "maintenance_required": args.maintenance_required or 0, diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json index 95cde401589b0bf56a9fee1216e8d1a75bba3524..3a540d82d0407d637b3bf907eb4d6c72eb17111f 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json @@ -13,7 +13,7 @@ "column_break_2", "gross_purchase_amount", "opening_accumulated_depreciation", - "number_of_depreciations_booked", + "opening_number_of_booked_depreciations", "finance_book", "finance_book_id", "depreciation_details_section", @@ -171,10 +171,10 @@ "read_only": 1 }, { - "fieldname": "number_of_depreciations_booked", + "fieldname": "opening_number_of_booked_depreciations", "fieldtype": "Int", "hidden": 1, - "label": "Number of Depreciations Booked", + "label": "Opening Number of Booked Depreciations", "print_hide": 1, "read_only": 1 }, diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index afd80271a62fd84f1e1729fb9bc4e772bbf6b212..eb0135033b0e8fbf40251295767a87a2b2990cef 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -50,7 +50,7 @@ class AssetDepreciationSchedule(Document): gross_purchase_amount: DF.Currency naming_series: DF.Literal["ACC-ADS-.YYYY.-"] notes: DF.SmallText | None - number_of_depreciations_booked: DF.Int + opening_number_of_booked_depreciations: DF.Int opening_accumulated_depreciation: DF.Currency rate_of_depreciation: DF.Percent shift_based: DF.Check @@ -161,7 +161,7 @@ class AssetDepreciationSchedule(Document): return ( asset_doc.gross_purchase_amount != self.gross_purchase_amount or asset_doc.opening_accumulated_depreciation != self.opening_accumulated_depreciation - or asset_doc.number_of_depreciations_booked != self.number_of_depreciations_booked + or asset_doc.opening_number_of_booked_depreciations != self.opening_number_of_booked_depreciations ) def not_manual_depr_or_have_manual_depr_details_been_modified(self, row): @@ -194,7 +194,7 @@ class AssetDepreciationSchedule(Document): self.finance_book = row.finance_book self.finance_book_id = row.idx self.opening_accumulated_depreciation = asset_doc.opening_accumulated_depreciation or 0 - self.number_of_depreciations_booked = asset_doc.number_of_depreciations_booked or 0 + self.opening_number_of_booked_depreciations = asset_doc.opening_number_of_booked_depreciations or 0 self.gross_purchase_amount = asset_doc.gross_purchase_amount self.depreciation_method = row.depreciation_method self.total_number_of_depreciations = row.total_number_of_depreciations @@ -263,7 +263,7 @@ class AssetDepreciationSchedule(Document): row.db_update() final_number_of_depreciations = cint(row.total_number_of_depreciations) - cint( - self.number_of_depreciations_booked + self.opening_number_of_booked_depreciations ) has_pro_rata = _check_is_pro_rata(asset_doc, row) @@ -328,7 +328,7 @@ class AssetDepreciationSchedule(Document): if date_of_disposal and getdate(schedule_date) >= getdate(date_of_disposal): from_date = add_months( getdate(asset_doc.available_for_use_date), - (asset_doc.number_of_depreciations_booked * row.frequency_of_depreciation), + (asset_doc.opening_number_of_booked_depreciations * row.frequency_of_depreciation), ) if self.depreciation_schedule: from_date = self.depreciation_schedule[-1].schedule_date @@ -378,13 +378,16 @@ class AssetDepreciationSchedule(Document): from_date = get_last_day( add_months( getdate(asset_doc.available_for_use_date), - ((self.number_of_depreciations_booked - 1) * row.frequency_of_depreciation), + ( + (self.opening_number_of_booked_depreciations - 1) + * row.frequency_of_depreciation + ), ) ) else: from_date = add_months( getdate(add_days(asset_doc.available_for_use_date, -1)), - (self.number_of_depreciations_booked * row.frequency_of_depreciation), + (self.opening_number_of_booked_depreciations * row.frequency_of_depreciation), ) depreciation_amount, days, months = _get_pro_rata_amt( row, @@ -400,7 +403,8 @@ class AssetDepreciationSchedule(Document): # In case of increase_in_asset_life, the asset.to_date is already set on asset_repair submission asset_doc.to_date = add_months( asset_doc.available_for_use_date, - (n + self.number_of_depreciations_booked) * cint(row.frequency_of_depreciation), + (n + self.opening_number_of_booked_depreciations) + * cint(row.frequency_of_depreciation), ) depreciation_amount_without_pro_rata = depreciation_amount @@ -546,7 +550,7 @@ def _check_is_pro_rata(asset_doc, row, wdv_or_dd_non_yearly=False): has_pro_rata = False # 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 + # otherwise, if opening_number_of_booked_depreciations = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12 # from_date = 01/01/2022 from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly) days = date_diff(row.depreciation_start_date, from_date) + 1 @@ -567,12 +571,12 @@ def _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly=Fa if wdv_or_dd_non_yearly: return add_months( asset_doc.available_for_use_date, - (asset_doc.number_of_depreciations_booked * 12), + (asset_doc.opening_number_of_booked_depreciations * 12), ) else: return add_months( asset_doc.available_for_use_date, - (asset_doc.number_of_depreciations_booked * row.frequency_of_depreciation), + (asset_doc.opening_number_of_booked_depreciations * row.frequency_of_depreciation), ) @@ -687,7 +691,7 @@ def get_straight_line_or_manual_depr_amount( flt(asset.gross_purchase_amount) - flt(asset.opening_accumulated_depreciation) - flt(row.expected_value_after_useful_life) - ) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked) + ) / flt(row.total_number_of_depreciations - asset.opening_number_of_booked_depreciations) def get_daily_prorata_based_straight_line_depr( @@ -713,7 +717,7 @@ def get_shift_depr_amount(asset_depr_schedule, asset, row, schedule_idx): flt(asset.gross_purchase_amount) - flt(asset.opening_accumulated_depreciation) - flt(row.expected_value_after_useful_life) - ) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked) + ) / flt(row.total_number_of_depreciations - asset.opening_number_of_booked_depreciations) asset_shift_factors_map = get_asset_shift_factors_map() shift = ( diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py index 6e4966ac6cfa238e0684636426b294d9ff8b3a56..6009ac1496cb67483ec24f29755a1c238acb9369 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py @@ -5,6 +5,9 @@ import frappe from frappe.tests.utils import FrappeTestCase from frappe.utils import cstr +from erpnext.assets.doctype.asset.depreciation import ( + post_depreciation_entries, +) from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_asset_depr_schedule_doc, @@ -28,7 +31,7 @@ class TestAssetDepreciationSchedule(FrappeTestCase): self.assertRaises(frappe.ValidationError, second_asset_depr_schedule.insert) - def test_daily_prorata_based_depr_on_sl_methond(self): + def test_daily_prorata_based_depr_on_sl_method(self): asset = create_asset( calculate_depreciation=1, depreciation_method="Straight Line", @@ -160,3 +163,35 @@ class TestAssetDepreciationSchedule(FrappeTestCase): for d in get_depr_schedule(asset.name, "Draft") ] self.assertEqual(schedules, expected_schedules) + + def test_update_total_number_of_booked_depreciations(self): + # check if updates total number of booked depreciations when depreciation gets booked + asset = create_asset( + item_code="Macbook Pro", + calculate_depreciation=1, + opening_accumulated_depreciation=2000, + opening_number_of_booked_depreciations=2, + depreciation_method="Straight Line", + available_for_use_date="2020-03-01", + depreciation_start_date="2020-03-31", + frequency_of_depreciation=1, + total_number_of_depreciations=24, + submit=1, + ) + + post_depreciation_entries(date="2021-03-31") + asset.reload() + """ + opening_number_of_booked_depreciations = 2 + number_of_booked_depreciations till 2021-03-31 = 13 + total_number_of_booked_depreciations = 15 + """ + self.assertEqual(asset.finance_books[0].total_number_of_booked_depreciations, 15) + + # cancel depreciation entry + depr_entry = get_depr_schedule(asset.name, "Active")[0].journal_entry + + frappe.get_doc("Journal Entry", depr_entry).cancel() + asset.reload() + + self.assertEqual(asset.finance_books[0].total_number_of_booked_depreciations, 14) diff --git a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json index 345ec78fa673ae5548b847d27411666982441a43..779749ee4eb0651e79418797f19faffb7712e9c9 100644 --- a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json +++ b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json @@ -8,6 +8,7 @@ "finance_book", "depreciation_method", "total_number_of_depreciations", + "total_number_of_booked_depreciations", "daily_prorata_based", "shift_based", "column_break_5", @@ -104,12 +105,19 @@ "fieldname": "shift_based", "fieldtype": "Check", "label": "Depreciate based on shifts" + }, + { + "default": "0", + "fieldname": "total_number_of_booked_depreciations", + "fieldtype": "Int", + "label": "Total Number of Booked Depreciations ", + "read_only": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2024-03-27 13:06:34.342264", + "modified": "2024-05-21 15:48:20.907250", "modified_by": "Administrator", "module": "Assets", "name": "Asset Finance Book", diff --git a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.py b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.py index f812a0816dd4ecc6af528e6f1ef27bdbdebacad7..d06d6355ec34924efbb85cf044242a490ba8f504 100644 --- a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.py +++ b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.py @@ -28,6 +28,7 @@ class AssetFinanceBook(Document): rate_of_depreciation: DF.Percent salvage_value_percentage: DF.Percent shift_based: DF.Check + total_number_of_booked_depreciations: DF.Int total_number_of_depreciations: DF.Int value_after_depreciation: DF.Currency # end: auto-generated types diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 27542bc6de8f874f34a96ec20b992659f81976c9..ccde836fe0d7a6b9b8b6fe29890cb6a05444799e 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -377,7 +377,7 @@ class AssetRepair(AccountsController): def calculate_last_schedule_date(self, asset, row, extra_months): asset.flags.increase_in_asset_life = True number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint( - asset.number_of_depreciations_booked + asset.opening_number_of_booked_depreciations ) depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book) @@ -410,7 +410,7 @@ class AssetRepair(AccountsController): def calculate_last_schedule_date_before_modification(self, asset, row, extra_months): asset.flags.increase_in_asset_life = True number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint( - asset.number_of_depreciations_booked + asset.opening_number_of_booked_depreciations ) depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c414dc4f4896f08523b7a4934a79458b97f5cdf5..ad1d0a98b93d3c99173af386b2366fc9af92df3d 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -398,3 +398,4 @@ erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency erpnext.patches.v15_0.rename_purchase_receipt_amount_to_purchase_amount erpnext.patches.v14_0.enable_set_priority_for_pricing_rules #1 +erpnext.patches.v15_0.rename_number_of_depreciations_booked_to_opening_booked_depreciations diff --git a/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py b/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py index bc0fd2871ac6b53f25d0a8bf1f74124c3ee15caf..3087ff020985771eac0b0fad6b13099b005525ff 100644 --- a/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py +++ b/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py @@ -43,7 +43,7 @@ def get_details_of_draft_or_submitted_depreciable_assets(): asset.name, asset.opening_accumulated_depreciation, asset.gross_purchase_amount, - asset.number_of_depreciations_booked, + asset.opening_number_of_booked_depreciations, asset.docstatus, ) .where(asset.calculate_depreciation == 1) diff --git a/erpnext/patches/v15_0/rename_number_of_depreciations_booked_to_opening_booked_depreciations.py b/erpnext/patches/v15_0/rename_number_of_depreciations_booked_to_opening_booked_depreciations.py new file mode 100644 index 0000000000000000000000000000000000000000..18183374554683d1e78d59c513a18809cb587890 --- /dev/null +++ b/erpnext/patches/v15_0/rename_number_of_depreciations_booked_to_opening_booked_depreciations.py @@ -0,0 +1,7 @@ +import frappe +from frappe.model.utils.rename_field import rename_field + + +def execute(): + if frappe.db.has_column("Asset", "number_of_depreciations_booked"): + rename_field("Asset", "number_of_depreciations_booked", "opening_number_of_booked_depreciations") diff --git a/erpnext/patches/v15_0/update_gpa_and_ndb_for_assdeprsch.py b/erpnext/patches/v15_0/update_gpa_and_ndb_for_assdeprsch.py index 2198be73d8a324ecbe2183606fe60b65cd93cfbb..4399a95fda2d4ff45e65702d14460c4716bcd738 100644 --- a/erpnext/patches/v15_0/update_gpa_and_ndb_for_assdeprsch.py +++ b/erpnext/patches/v15_0/update_gpa_and_ndb_for_assdeprsch.py @@ -5,16 +5,16 @@ def execute(): # not using frappe.qb because https://github.com/frappe/frappe/issues/20292 frappe.db.sql( """UPDATE `tabAsset Depreciation Schedule` - JOIN `tabAsset` - ON `tabAsset Depreciation Schedule`.`asset`=`tabAsset`.`name` - SET - `tabAsset Depreciation Schedule`.`gross_purchase_amount`=`tabAsset`.`gross_purchase_amount`, - `tabAsset Depreciation Schedule`.`number_of_depreciations_booked`=`tabAsset`.`number_of_depreciations_booked` - WHERE - ( - `tabAsset Depreciation Schedule`.`gross_purchase_amount`<>`tabAsset`.`gross_purchase_amount` - OR - `tabAsset Depreciation Schedule`.`number_of_depreciations_booked`<>`tabAsset`.`number_of_depreciations_booked` - ) - AND `tabAsset Depreciation Schedule`.`docstatus`<2""" + JOIN `tabAsset` + ON `tabAsset Depreciation Schedule`.`asset`=`tabAsset`.`name` + SET + `tabAsset Depreciation Schedule`.`gross_purchase_amount`=`tabAsset`.`gross_purchase_amount`, + `tabAsset Depreciation Schedule`.`opening_number_of_booked_depreciations`=`tabAsset`.`opening_number_of_booked_depreciations` + WHERE + ( + `tabAsset Depreciation Schedule`.`gross_purchase_amount`<>`tabAsset`.`gross_purchase_amount` + OR + `tabAsset Depreciation Schedule`.`opening_number_of_booked_depreciations`<>`tabAsset`.`opening_number_of_booked_depreciations` + ) + AND `tabAsset Depreciation Schedule`.`docstatus`<2""" )