fix: Cancel asset capitalisation record on cancellation of asset and vice-versa
(cherry picked from commit efe9f6656f01c46a6ac02e3bb61851564670d6bc)
This commit is contained in:
		
							parent
							
								
									53f61f1ad1
								
							
						
					
					
						commit
						011c5a69f0
					
				| @ -202,8 +202,7 @@ | |||||||
|    "fieldname": "purchase_date", |    "fieldname": "purchase_date", | ||||||
|    "fieldtype": "Date", |    "fieldtype": "Date", | ||||||
|    "label": "Purchase Date", |    "label": "Purchase Date", | ||||||
|    "mandatory_depends_on": "eval:!doc.is_existing_asset", |    "mandatory_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset", | ||||||
|    "read_only": 1, |  | ||||||
|    "read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset" |    "read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset" | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
| @ -590,7 +589,7 @@ | |||||||
|    "link_fieldname": "target_asset" |    "link_fieldname": "target_asset" | ||||||
|   } |   } | ||||||
|  ], |  ], | ||||||
|  "modified": "2024-01-05 17:36:53.131512", |  "modified": "2024-01-15 17:35:49.226603", | ||||||
|  "modified_by": "Administrator", |  "modified_by": "Administrator", | ||||||
|  "module": "Assets", |  "module": "Assets", | ||||||
|  "name": "Asset", |  "name": "Asset", | ||||||
|  | |||||||
| @ -162,6 +162,7 @@ class Asset(AccountsController): | |||||||
| 	def on_cancel(self): | 	def on_cancel(self): | ||||||
| 		self.validate_cancellation() | 		self.validate_cancellation() | ||||||
| 		self.cancel_movement_entries() | 		self.cancel_movement_entries() | ||||||
|  | 		self.cancel_capitalization() | ||||||
| 		self.delete_depreciation_entries() | 		self.delete_depreciation_entries() | ||||||
| 		cancel_asset_depr_schedules(self) | 		cancel_asset_depr_schedules(self) | ||||||
| 		self.set_status() | 		self.set_status() | ||||||
| @ -517,6 +518,16 @@ class Asset(AccountsController): | |||||||
| 			movement = frappe.get_doc("Asset Movement", movement.get("name")) | 			movement = frappe.get_doc("Asset Movement", movement.get("name")) | ||||||
| 			movement.cancel() | 			movement.cancel() | ||||||
| 
 | 
 | ||||||
|  | 	def cancel_capitalization(self): | ||||||
|  | 		asset_capitalization = frappe.db.get_value( | ||||||
|  | 			"Asset Capitalization", | ||||||
|  | 			{"target_asset": self.name, "docstatus": 1, "entry_type": "Capitalization"}, | ||||||
|  | 		) | ||||||
|  | 
 | ||||||
|  | 		if asset_capitalization: | ||||||
|  | 			asset_capitalization = frappe.get_doc("Asset Capitalization", asset_capitalization) | ||||||
|  | 			asset_capitalization.cancel() | ||||||
|  | 
 | ||||||
| 	def delete_depreciation_entries(self): | 	def delete_depreciation_entries(self): | ||||||
| 		if self.calculate_depreciation: | 		if self.calculate_depreciation: | ||||||
| 			for row in self.get("finance_books"): | 			for row in self.get("finance_books"): | ||||||
|  | |||||||
| @ -136,11 +136,19 @@ class AssetCapitalization(StockController): | |||||||
| 			"Stock Ledger Entry", | 			"Stock Ledger Entry", | ||||||
| 			"Repost Item Valuation", | 			"Repost Item Valuation", | ||||||
| 			"Serial and Batch Bundle", | 			"Serial and Batch Bundle", | ||||||
|  | 			"Asset", | ||||||
| 		) | 		) | ||||||
|  | 		self.cancel_target_asset() | ||||||
| 		self.update_stock_ledger() | 		self.update_stock_ledger() | ||||||
| 		self.make_gl_entries() | 		self.make_gl_entries() | ||||||
| 		self.restore_consumed_asset_items() | 		self.restore_consumed_asset_items() | ||||||
| 
 | 
 | ||||||
|  | 	def cancel_target_asset(self): | ||||||
|  | 		if self.entry_type == "Capitalization" and self.target_asset: | ||||||
|  | 			asset_doc = frappe.get_doc("Asset", self.target_asset) | ||||||
|  | 			if asset_doc.docstatus == 1: | ||||||
|  | 				asset_doc.cancel() | ||||||
|  | 
 | ||||||
| 	def set_title(self): | 	def set_title(self): | ||||||
| 		self.title = self.target_asset_name or self.target_item_name or self.target_item_code | 		self.title = self.target_asset_name or self.target_item_name or self.target_item_code | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user