[fix] Validate company abbr
This commit is contained in:
		
							parent
							
								
									8b92de26f0
								
							
						
					
					
						commit
						afb8ec9cb6
					
				| @ -27,15 +27,21 @@ class Company(Document): | ||||
| 		return exists | ||||
| 
 | ||||
| 	def validate(self): | ||||
| 		self.validate_abbr() | ||||
| 		self.validate_default_accounts() | ||||
| 		self.validate_currency() | ||||
| 		 | ||||
| 	def validate_abbr(self): | ||||
| 		self.abbr = self.abbr.strip() | ||||
| 		 | ||||
| 		if self.get('__islocal') and len(self.abbr) > 5: | ||||
| 			frappe.throw(_("Abbreviation cannot have more than 5 characters")) | ||||
| 
 | ||||
| 		if not self.abbr.strip(): | ||||
| 			frappe.throw(_("Abbreviation is mandatory")) | ||||
| 
 | ||||
| 		self.validate_default_accounts() | ||||
| 		self.validate_currency() | ||||
| 			 | ||||
| 		if frappe.db.sql("select abbr from tabCompany where name!=%s and abbr=%s", (self.name, self.abbr)): | ||||
| 			frappe.throw(_("Abbreviation already used for another company")) | ||||
| 
 | ||||
| 	def validate_default_accounts(self): | ||||
| 		for field in ["default_bank_account", "default_cash_account", "default_receivable_account", "default_payable_account", | ||||
| @ -167,7 +173,7 @@ class Company(Document): | ||||
| 		frappe.defaults.clear_cache() | ||||
| 
 | ||||
| 	def abbreviate(self): | ||||
| 		self.abbr = ''.join([c[0].upper() for c in self.name.split()]) | ||||
| 		self.abbr = ''.join([c[0].upper() for c in self.company_name.split()]) | ||||
| 
 | ||||
| 	def on_trash(self): | ||||
| 		""" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user