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

chore: patch to enable total number of booked depreciations field (backport #41940) #42042

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def on_cancel(self):
self.unlink_inter_company_jv()
self.unlink_asset_adjustment_entry()
self.update_invoice_discounting()
self.update_booked_depreciation()
self.update_booked_depreciation(1)

def get_title(self):
return self.pay_to_recd_from or self.accounts[0].account
Expand Down Expand Up @@ -441,7 +441,7 @@ def _validate_invoice_discounting_status(inv_disc, id_status, expected_status, r
if status:
inv_disc_doc.set_status(status=status)

def update_booked_depreciation(self):
def update_booked_depreciation(self, cancel=0):
for d in self.get("accounts"):
if (
self.voucher_type == "Depreciation Entry"
Expand All @@ -453,14 +453,11 @@ def update_booked_depreciation(self):
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
)
if cancel:
fb_row.total_number_of_booked_depreciations -= 1
else:
fb_row.total_number_of_booked_depreciations += 1
fb_row.db_update()
break

def unlink_advance_entry_reference(self):
Expand Down
3 changes: 3 additions & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,6 @@ erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset
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
erpnext.patches.v15_0.add_default_operations
erpnext.patches.v15_0.enable_old_serial_batch_fields
erpnext.patches.v15_0.update_total_number_of_booked_depreciations
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import frappe

from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
get_depr_schedule,
)


def execute():
if frappe.db.has_column("Asset Finance Book", "total_number_of_booked_depreciations"):
assets = frappe.get_all(
"Asset", filters={"docstatus": 1}, fields=["name", "opening_number_of_booked_depreciations"]
)

for asset in assets:
asset_doc = frappe.get_doc("Asset", asset.name)

for fb_row in asset_doc.get("finance_books"):
depr_schedule = get_depr_schedule(asset.name, "Active", fb_row.finance_book)
total_number_of_booked_depreciations = asset.opening_number_of_booked_depreciations or 0

for je in depr_schedule:
if je.journal_entry:
total_number_of_booked_depreciations += 1
frappe.db.set_value(
"Asset Finance Book",
fb_row.name,
"total_number_of_booked_depreciations",
total_number_of_booked_depreciations,
)
Loading