mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-16 08:05:00 +00:00
refactor: Ensure flag cleanup with try-finally to prevent state corruption
This commit is contained in:
@@ -493,15 +493,17 @@ class AssetCapitalization(StockController):
|
||||
|
||||
if asset.calculate_depreciation:
|
||||
frappe.flags.is_composite_component = True
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was consumed through Asset Capitalization {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
frappe.flags.is_composite_component = False
|
||||
asset.reload()
|
||||
try:
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was consumed through Asset Capitalization {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
finally:
|
||||
frappe.flags.is_composite_component = False
|
||||
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
asset,
|
||||
|
||||
Reference in New Issue
Block a user