Test Cases added to check if customer is frozen

This commit is contained in:
Neil Trini Lasrado 2015-07-20 13:03:48 +05:30
parent 3698b84d7c
commit 79bf233734
3 changed files with 30 additions and 12 deletions

View File

@ -9,6 +9,8 @@ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
class CustomerFrozen(frappe.ValidationError): pass
class GLEntry(Document): class GLEntry(Document):
def validate(self): def validate(self):
self.flags.ignore_submit_comment = True 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)) frappe.throw(_("Cost Center {0} does not belong to Company {1}").format(self.cost_center, self.company))
def validate_party(self): 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"): 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): def validate_balance_type(account, adv_adj=False):
if not adv_adj and account: if not adv_adj and account:

View File

@ -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.recurring_document import convert_to_recurring, validate_recurring_document
from erpnext.controllers.sales_and_purchase_return import validate_return from erpnext.controllers.sales_and_purchase_return import validate_return
class CustomerFrozen(frappe.ValidationError): pass
class AccountsController(TransactionBase): class AccountsController(TransactionBase):
def validate(self): def validate(self):
if self.get("_action") and self._action != "update_after_submit": if self.get("_action") and self._action != "update_after_submit":
@ -344,18 +346,17 @@ class AccountsController(TransactionBase):
return self._abbr return self._abbr
def validate_party(self): def validate_party(self):
party = None party_type = None
if self.meta.get_field("customer"): if self.meta.get_field("customer"):
party_type = 'customer' party_type = 'Customer'
party = self.customer
elif self.meta.get_field("suppier"): elif self.meta.get_field("supplier"):
party_type = 'supplier' party_type = 'Supplier'
party = self.supplier
if party: if party_type:
party = self.get(party_type.lower())
if frappe.db.get_value(party_type, party, "is_frozen"): 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() @frappe.whitelist()
def get_tax_rate(account_head): def get_tax_rate(account_head):

View File

@ -7,6 +7,7 @@ import frappe
import unittest import unittest
from frappe.test_runner import make_test_records from frappe.test_runner import make_test_records
from erpnext.controllers.accounts_controller import CustomerFrozen
test_ignore = ["Price List"] test_ignore = ["Price List"]
@ -66,4 +67,18 @@ class TestCustomer(unittest.TestCase):
frappe.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1") 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()