From dc89916aa9751baba1ee088b444e1a1ce5e55502 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 31 Mar 2017 17:18:58 +0530 Subject: [PATCH] [fix] salary component fix for abbr --- .../hr/doctype/salary_component/salary_component.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/erpnext/hr/doctype/salary_component/salary_component.py b/erpnext/hr/doctype/salary_component/salary_component.py index c02d952ac1f..35d274cd604 100644 --- a/erpnext/hr/doctype/salary_component/salary_component.py +++ b/erpnext/hr/doctype/salary_component/salary_component.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -from frappe import _ +from frappe.model.naming import append_number_if_name_exists class SalaryComponent(Document): def validate(self): @@ -13,12 +13,10 @@ class SalaryComponent(Document): def validate_abbr(self): if not self.salary_component_abbr: - self.salary_component_abbr = ''.join([c[0] for c in self.salary_component.split()]).upper() + self.salary_component_abbr = ''.join([c[0] for c in + self.salary_component.split()]).upper() self.salary_component_abbr = self.salary_component_abbr.strip() - if self.get('__islocal') and len(self.salary_component_abbr) > 5: - frappe.throw(_("Abbreviation cannot have more than 5 characters")) - - if frappe.db.sql("select salary_component_abbr from `tabSalary Component` where name!=%s and salary_component_abbr=%s", (self.name, self.salary_component_abbr)): - frappe.throw(_("Abbreviation {0} already used for another salary component").format(self.salary_component_abbr)) \ No newline at end of file + self.salary_component_abbr = append_number_if_name_exists('Salary Component', + self.salary_component_abbr, 'salary_component_abbr', separator='_') \ No newline at end of file