mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 11:49:10 +00:00
[fixes and test case] test case to avoid duplicate customer name exection
This commit is contained in:
@@ -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, cint, cstr
|
from frappe.utils import flt, cint,
|
||||||
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,18 +23,18 @@ 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.get_cusotmer_name()
|
self.name = self.get_customer_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):
|
def get_customer_name(self):
|
||||||
if frappe.db.get_value("Customer", self.customer_name):
|
if frappe.db.get_value("Customer", self.customer_name):
|
||||||
count = frappe.db.sql("""select ifnull(max(SUBSTRING_INDEX(name, ' ', -1)), 0) from tabCustomer
|
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]
|
where name like '%{0} - %'""".format(self.customer_name), as_list=1)[0][0]
|
||||||
count = cint(count)+ 1
|
count = cint(count) + 1
|
||||||
return "{0} - {1}".format(self.customer_name, cstr(count))
|
return "{0} - {1}".format(self.customer_name, cstr(count))
|
||||||
|
|
||||||
return self.customer_name
|
return self.customer_name
|
||||||
|
|||||||
@@ -73,8 +73,33 @@ class TestCustomer(unittest.TestCase):
|
|||||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
|
|
||||||
so = make_sales_order(do_not_save= True)
|
so = make_sales_order(do_not_save= True)
|
||||||
|
|
||||||
self.assertRaises(CustomerFrozen, so.save)
|
self.assertRaises(CustomerFrozen, so.save)
|
||||||
|
|
||||||
frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 0)
|
frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 0)
|
||||||
|
|
||||||
so.save()
|
so.save()
|
||||||
|
|
||||||
|
def test_duplicate_customer(self):
|
||||||
|
if not frappe.db.get_value("Customer", "_Test Customer 1"):
|
||||||
|
test_customer_1 = frappe.get_doc({
|
||||||
|
"customer_group": "_Test Customer Group",
|
||||||
|
"customer_name": "_Test Customer 1",
|
||||||
|
"customer_type": "Individual",
|
||||||
|
"doctype": "Customer",
|
||||||
|
"territory": "_Test Territory"
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
else:
|
||||||
|
test_customer_1 = frappe.get_doc("Customer", "_Test Customer 1")
|
||||||
|
|
||||||
|
duplicate_customer = frappe.get_doc({
|
||||||
|
"customer_group": "_Test Customer Group",
|
||||||
|
"customer_name": "_Test Customer 1",
|
||||||
|
"customer_type": "Individual",
|
||||||
|
"doctype": "Customer",
|
||||||
|
"territory": "_Test Territory"
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
self.assertEquals("_Test Customer 1", test_customer_1.name)
|
||||||
|
self.assertEquals("_Test Customer 1 - 1", duplicate_customer.name)
|
||||||
|
self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name)
|
||||||
@@ -303,6 +303,7 @@ 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user