refactor: Ensure flag cleanup with try-finally to prevent state corruption

This commit is contained in:
khushi8112
2025-10-14 16:32:32 +05:30
parent 6d5f2b5024
commit 02ebde43bf

View File

@@ -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,