From 79bf2337341dd8aae21fe8e7e07ae30b55616ee1 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Mon, 20 Jul 2015 13:03:48 +0530 Subject: [PATCH] Test Cases added to check if customer is frozen --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 6 ++++-- erpnext/controllers/accounts_controller.py | 17 +++++++++-------- .../selling/doctype/customer/test_customer.py | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index de5b312287..d3246d7554 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -9,6 +9,8 @@ from frappe import _ from frappe.model.document import Document +class CustomerFrozen(frappe.ValidationError): pass + class GLEntry(Document): def validate(self): self.flags.ignore_submit_comment = True @@ -91,9 +93,9 @@ class GLEntry(Document): frappe.throw(_("Cost Center {0} does not belong to Company {1}").format(self.cost_center, self.company)) def validate_party(self): - if self.meta.get_field("party_type"): + if self.party_type and self.party: if frappe.db.get_value(self.party_type, self.party, "is_frozen"): - frappe.throw("Accounts for {0} {1} is frozen".format(self.party_type, self.party)) + frappe.throw("{0} {1} is frozen".format(self.party_type, self.party), CustomerFrozen) def validate_balance_type(account, adv_adj=False): if not adv_adj and account: diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index c893a0a09d..cbd8a6fb82 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -11,6 +11,8 @@ from erpnext.utilities.transaction_base import TransactionBase from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document from erpnext.controllers.sales_and_purchase_return import validate_return +class CustomerFrozen(frappe.ValidationError): pass + class AccountsController(TransactionBase): def validate(self): if self.get("_action") and self._action != "update_after_submit": @@ -344,18 +346,17 @@ class AccountsController(TransactionBase): return self._abbr def validate_party(self): - party = None + party_type = None if self.meta.get_field("customer"): - party_type = 'customer' - party = self.customer + party_type = 'Customer' - elif self.meta.get_field("suppier"): - party_type = 'supplier' - party = self.supplier + elif self.meta.get_field("supplier"): + party_type = 'Supplier' - if party: + if party_type: + party = self.get(party_type.lower()) if frappe.db.get_value(party_type, party, "is_frozen"): - frappe.throw("Accounts for {0} {1} is frozen".format(party_type, party)) + frappe.throw("{0} {1} is frozen".format(party_type, party), CustomerFrozen) @frappe.whitelist() def get_tax_rate(account_head): diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 1db6c6a24a..2f9c4e1270 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -7,6 +7,7 @@ import frappe import unittest from frappe.test_runner import make_test_records +from erpnext.controllers.accounts_controller import CustomerFrozen test_ignore = ["Price List"] @@ -65,5 +66,19 @@ class TestCustomer(unittest.TestCase): {"comment_doctype": "Customer", "comment_docname": "_Test Customer 1 Renamed"}), comment.name) frappe.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1") - - + + def test_freezed_customer(self): + cust = frappe.get_doc("Customer", "_Test Customer") + cust.is_frozen = 1 + cust.save() + + from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order + + so = make_sales_order(do_not_save= True) + so.customer = "_Test Customer" + self.assertRaises(CustomerFrozen, so.save) + + cust.is_frozen = 0 + cust.save() + + so.save() \ No newline at end of file