[fix] Duplicate Customer Name Error

This commit is contained in:
Saurabh 2015-10-14 16:13:43 +05:30
parent 9f235b891f
commit 53f7e6281c
2 changed files with 12 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import frappe
from frappe.model.naming import make_autoname from frappe.model.naming import make_autoname
from frappe import _, msgprint, throw from frappe import _, msgprint, throw
import frappe.defaults import frappe.defaults
from frappe.utils import flt from frappe.utils import flt, cint, cstr
from frappe.desk.reportview import build_match_conditions from frappe.desk.reportview import build_match_conditions
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.utilities.address_and_contact import load_address_and_contact
@ -23,12 +23,21 @@ class Customer(TransactionBase):
def autoname(self): def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name') cust_master_name = frappe.defaults.get_global_default('cust_master_name')
if cust_master_name == 'Customer Name': if cust_master_name == 'Customer Name':
self.name = self.customer_name self.name = self.get_cusotmer_name()
else: else:
if not self.naming_series: if not self.naming_series:
frappe.throw(_("Series is mandatory"), frappe.MandatoryError) frappe.throw(_("Series is mandatory"), frappe.MandatoryError)
self.name = make_autoname(self.naming_series+'.#####') self.name = make_autoname(self.naming_series+'.#####')
def get_cusotmer_name(self):
if frappe.db.get_value("Customer", self.customer_name):
count = frappe.db.sql("""select ifnull(max(SUBSTRING_INDEX(name, ' ', -1)), 0) from tabCustomer
where name like '%{0} - %'""".format(self.customer_name), as_list=1)[0][0]
count = cint(count)+ 1
return "{0} - {1}".format(self.customer_name, cstr(count))
return self.customer_name
def validate(self): def validate(self):
self.flags.is_new_doc = self.is_new() self.flags.is_new_doc = self.is_new()
@ -225,4 +234,4 @@ def get_credit_limit(customer, company):
credit_limit = frappe.db.get_value("Customer Group", customer_group, "credit_limit") or \ credit_limit = frappe.db.get_value("Customer Group", customer_group, "credit_limit") or \
frappe.db.get_value("Company", company, "credit_limit") frappe.db.get_value("Company", company, "credit_limit")
return credit_limit return credit_limit

View File

@ -303,7 +303,6 @@ def get_customer(user=None):
contact.insert(ignore_permissions=True) contact.insert(ignore_permissions=True)
return customer return customer
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None): def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
if not party: if not party:
party = get_customer() party = get_customer()