chore: Break into smaller functions
This commit is contained in:
		
							parent
							
								
									e626107d3d
								
							
						
					
					
						commit
						42e4c37f15
					
				| @ -551,31 +551,38 @@ class SalesInvoice(SellingController): | |||||||
| 					needs_repost = 1 | 					needs_repost = 1 | ||||||
| 					break | 					break | ||||||
| 
 | 
 | ||||||
| 			# Check for parent level | 			# Check for child tables | ||||||
| 			for index, item in enumerate(self.get("items")): | 			if self.check_if_child_table_updated( | ||||||
| 				for field in ("income_account", "expense_account", "discount_account"): | 				"items", | ||||||
| 					if doc_before_update.get("items")[index].get(field) != item.get(field): | 				doc_before_update, | ||||||
|  | 				("income_account", "expense_account", "discount_account"), | ||||||
|  | 				accounting_dimensions, | ||||||
|  | 			): | ||||||
| 				needs_repost = 1 | 				needs_repost = 1 | ||||||
| 						break |  | ||||||
| 
 | 
 | ||||||
| 				for dimension in accounting_dimensions: | 			if self.check_if_child_table_updated( | ||||||
| 					if doc_before_update.get("items")[index].get(dimension) != item.get(dimension): | 				"taxes", doc_before_update, ("account_head",), accounting_dimensions | ||||||
|  | 			): | ||||||
| 				needs_repost = 1 | 				needs_repost = 1 | ||||||
| 						break |  | ||||||
| 
 |  | ||||||
| 			for index, tax in enumerate(self.get("taxes")): |  | ||||||
| 				if doc_before_update.get("taxes")[index].get("account_head") != tax.get("account_head"): |  | ||||||
| 					needs_repost = 1 |  | ||||||
| 					break |  | ||||||
| 
 |  | ||||||
| 				for dimension in accounting_dimensions: |  | ||||||
| 					if doc_before_update.get("taxes")[index].get(dimension) != tax.get(dimension): |  | ||||||
| 						needs_repost = 1 |  | ||||||
| 						break |  | ||||||
| 
 | 
 | ||||||
| 		self.validate_accounts() | 		self.validate_accounts() | ||||||
| 		self.db_set("repost_required", needs_repost) | 		self.db_set("repost_required", needs_repost) | ||||||
| 
 | 
 | ||||||
|  | 	def check_if_child_table_updated( | ||||||
|  | 		self, child_table, doc_before_update, fields_to_check, accounting_dimensions | ||||||
|  | 	): | ||||||
|  | 		# Check if any field affecting accounting entry is altered | ||||||
|  | 		for index, item in enumerate(self.get(child_table)): | ||||||
|  | 			for field in fields_to_check: | ||||||
|  | 				if doc_before_update.get(child_table)[index].get(field) != item.get(field): | ||||||
|  | 					return True | ||||||
|  | 
 | ||||||
|  | 			for dimension in accounting_dimensions: | ||||||
|  | 				if doc_before_update.get(child_table)[index].get(dimension) != item.get(dimension): | ||||||
|  | 					return True | ||||||
|  | 
 | ||||||
|  | 		return False | ||||||
|  | 
 | ||||||
| 	@frappe.whitelist() | 	@frappe.whitelist() | ||||||
| 	def repost_accounting_entries(self): | 	def repost_accounting_entries(self): | ||||||
| 		self.docstatus = 2 | 		self.docstatus = 2 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user