From 9f235b891fb2267746ee611c4d640a822de46939 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 14 Oct 2015 13:40:45 +0530 Subject: [PATCH 1/4] [fix] order.html rate display --- erpnext/templates/pages/order.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index 73763921f8..046e6f6f04 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -53,8 +53,10 @@
{{ d.get_formatted("amount") }} +

{{ - _("Rate: {0}").format(d.get_formatted("rate")) }}

+ _("Rate: {0}").decode("utf8").format(d.get_formatted("rate")) }}

{% endfor %} From 53f7e6281cd3d625190b7a70d511a1707b7cb45e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 14 Oct 2015 16:13:43 +0530 Subject: [PATCH 2/4] [fix] Duplicate Customer Name Error --- erpnext/selling/doctype/customer/customer.py | 15 ++++++++++++--- erpnext/shopping_cart/cart.py | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 21f6578df4..e219fdb475 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -6,7 +6,7 @@ import frappe from frappe.model.naming import make_autoname from frappe import _, msgprint, throw import frappe.defaults -from frappe.utils import flt +from frappe.utils import flt, cint, cstr from frappe.desk.reportview import build_match_conditions from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.address_and_contact import load_address_and_contact @@ -23,12 +23,21 @@ class Customer(TransactionBase): def autoname(self): cust_master_name = frappe.defaults.get_global_default('cust_master_name') if cust_master_name == 'Customer Name': - self.name = self.customer_name + self.name = self.get_cusotmer_name() else: if not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) 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): 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 \ frappe.db.get_value("Company", company, "credit_limit") - return credit_limit + return credit_limit \ No newline at end of file diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 22f920faa6..aa6e5e3ae5 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -303,7 +303,6 @@ def get_customer(user=None): contact.insert(ignore_permissions=True) return customer - def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None): if not party: party = get_customer() From 4c539313639c4d4dd13301304737b29cd7ad8748 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 14 Oct 2015 17:37:05 +0530 Subject: [PATCH 3/4] [fixes and test case] test case to avoid duplicate customer name exection --- erpnext/selling/doctype/customer/customer.py | 8 +++--- .../selling/doctype/customer/test_customer.py | 25 +++++++++++++++++++ erpnext/shopping_cart/cart.py | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index e219fdb475..040e3b1041 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -6,7 +6,7 @@ import frappe from frappe.model.naming import make_autoname from frappe import _, msgprint, throw 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 erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.address_and_contact import load_address_and_contact @@ -23,18 +23,18 @@ class Customer(TransactionBase): def autoname(self): cust_master_name = frappe.defaults.get_global_default('cust_master_name') if cust_master_name == 'Customer Name': - self.name = self.get_cusotmer_name() + self.name = self.get_customer_name() else: if not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) 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): 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 + count = cint(count) + 1 return "{0} - {1}".format(self.customer_name, cstr(count)) return self.customer_name diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index f18194f3ab..9972ae8fce 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -73,8 +73,33 @@ class TestCustomer(unittest.TestCase): from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order so = make_sales_order(do_not_save= True) + self.assertRaises(CustomerFrozen, so.save) frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 0) 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) \ No newline at end of file diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index aa6e5e3ae5..22f920faa6 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -303,6 +303,7 @@ def get_customer(user=None): contact.insert(ignore_permissions=True) return customer + def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None): if not party: party = get_customer() From c0cee8272799bc4870ffa56895263699937dc3ee Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 14 Oct 2015 18:02:45 +0530 Subject: [PATCH 4/4] [small fixes] frozen customer testcase --- erpnext/selling/doctype/customer/customer.py | 2 +- erpnext/selling/doctype/customer/test_customer.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 040e3b1041..01e4813e94 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -6,7 +6,7 @@ import frappe from frappe.model.naming import make_autoname from frappe import _, msgprint, throw import frappe.defaults -from frappe.utils import flt, cint, +from frappe.utils import flt, cint, cstr from frappe.desk.reportview import build_match_conditions from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.address_and_contact import load_address_and_contact diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 9972ae8fce..0bbe534810 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -68,6 +68,9 @@ class TestCustomer(unittest.TestCase): frappe.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1") def test_freezed_customer(self): + make_test_records("Customer") + make_test_records("Item") + frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 1) from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order @@ -91,7 +94,7 @@ class TestCustomer(unittest.TestCase): }).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", @@ -99,7 +102,7 @@ class TestCustomer(unittest.TestCase): "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) \ No newline at end of file + self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name) \ No newline at end of file