From d3daeaf475d95f567dc6ed0a434f678b32260654 Mon Sep 17 00:00:00 2001 From: Bhavan23 Date: Wed, 18 Jun 2025 10:54:24 +0530 Subject: [PATCH] fix(asset-invoice): handle asset invoice cancellation --- .../doctype/sales_invoice/sales_invoice.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 5c6ed7a1320..b12f51e8a4b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1356,7 +1356,9 @@ class SalesInvoice(SellingController): if item.is_fixed_asset: asset = self.get_asset(item) - if self.is_return: + if (self.docstatus == 2 and not self.is_return) or ( + self.docstatus == 1 and self.is_return + ): fixed_asset_gl_entries = get_gl_entries_on_asset_regain( asset, item.base_net_amount, @@ -1369,8 +1371,10 @@ class SalesInvoice(SellingController): add_asset_activity(asset.name, _("Asset returned")) if asset.calculate_depreciation: - posting_date = frappe.db.get_value( - "Sales Invoice", self.return_against, "posting_date" + posting_date = ( + frappe.db.get_value("Sales Invoice", self.return_against, "posting_date") + if self.is_return + else self.posting_date ) reverse_depreciation_entry_made_after_disposal(asset, posting_date) notes = _( @@ -1467,8 +1471,10 @@ class SalesInvoice(SellingController): return self._enable_discount_accounting def set_asset_status(self, asset): - if self.is_return: + if self.is_return and not self.docstatus == 2: asset.set_status() + elif self.is_return and self.docstatus == 2: + asset.set_status("Sold") else: asset.set_status("Sold" if self.docstatus == 1 else None)