Merge pull request #3679 from neilLasrado/freeze-customer
Added ability to freeze Customer/Supplier
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index edee122..43c4213 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -4,11 +4,13 @@
from __future__ import unicode_literals
import frappe
-from frappe.utils import flt, fmt_money, getdate, formatdate, cstr, cint
+from frappe.utils import flt, fmt_money, getdate, formatdate, cstr
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
@@ -17,6 +19,7 @@
self.validate_posting_date()
self.check_pl_account()
self.validate_cost_center()
+ self.validate_party()
def on_update_with_args(self, adv_adj, update_outstanding = 'Yes'):
self.validate_account_details(adv_adj)
@@ -88,6 +91,13 @@
if self.cost_center and _get_cost_center_company() != self.company:
frappe.throw(_("Cost Center {0} does not belong to Company {1}").format(self.cost_center, self.company))
+
+ def validate_party(self):
+ if self.party_type and self.party:
+ frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
+ if not frozen_accounts_modifier in frappe.get_roles():
+ if frappe.db.get_value(self.party_type, self.party, "is_frozen"):
+ 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/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json
index a1a38d5..c3128a5 100644
--- a/erpnext/buying/doctype/supplier/supplier.json
+++ b/erpnext/buying/doctype/supplier/supplier.json
@@ -55,6 +55,13 @@
"reqd": 1
},
{
+ "fieldname": "is_frozen",
+ "fieldtype": "Check",
+ "label": "Is Frozen",
+ "permlevel": 0,
+ "precision": ""
+ },
+ {
"depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts",
"fieldtype": "Section Break",
@@ -172,7 +179,7 @@
],
"icon": "icon-user",
"idx": 1,
- "modified": "2015-07-13 05:28:29.121285",
+ "modified": "2015-07-17 09:39:05.318826",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier",
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 7610042..55e9e3d 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -11,11 +11,14 @@
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":
self.set_missing_values(for_validate=True)
self.validate_date_with_fiscal_year()
+
if self.meta.get_field("currency"):
self.calculate_taxes_and_totals()
if not self.meta.get_field("is_return") or not self.is_return:
@@ -32,6 +35,8 @@
if self.meta.get_field("taxes_and_charges"):
self.validate_enabled_taxes_and_charges()
+
+ self.validate_party()
def on_submit(self):
if self.meta.get_field("is_recurring"):
@@ -340,6 +345,23 @@
return self._abbr
+ def validate_party(self):
+ frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
+ if frozen_accounts_modifier in frappe.get_roles():
+ return
+
+ party_type = None
+ if self.meta.get_field("customer"):
+ party_type = 'Customer'
+
+ elif self.meta.get_field("supplier"):
+ party_type = 'Supplier'
+
+ if party_type:
+ party = self.get(party_type.lower())
+ if frappe.db.get_value(party_type, party, "is_frozen"):
+ frappe.throw("{0} {1} is frozen".format(party_type, party), CustomerFrozen)
+
@frappe.whitelist()
def get_tax_rate(account_head):
return frappe.db.get_value("Account", account_head, "tax_rate")
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index cced319..a3bcc8a 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -102,6 +102,13 @@
"reqd": 1
},
{
+ "fieldname": "is_frozen",
+ "fieldtype": "Check",
+ "label": "Is Frozen",
+ "permlevel": 0,
+ "precision": ""
+ },
+ {
"depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts",
"fieldtype": "Section Break",
@@ -278,7 +285,7 @@
],
"icon": "icon-user",
"idx": 1,
- "modified": "2015-07-13 05:28:25.753684",
+ "modified": "2015-07-17 09:38:50.086978",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",
diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py
index 1db6c6a..dca4bb7 100644
--- a/erpnext/selling/doctype/customer/test_customer.py
+++ b/erpnext/selling/doctype/customer/test_customer.py
@@ -7,6 +7,7 @@
import unittest
from frappe.test_runner import make_test_records
+from erpnext.controllers.accounts_controller import CustomerFrozen
test_ignore = ["Price List"]
@@ -65,5 +66,15 @@
{"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):
+ frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 1)
+
+ 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()
\ No newline at end of file