From b161eea793fbc1fd9707fbed5c156655f2710c99 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Jun 2014 12:51:16 +0530 Subject: [PATCH] Account balance must be debit / credit, validate if balance already in credit / debit. Fixes #1442 --- erpnext/accounts/doctype/account/account.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index c551a62aaa..e5e2e41feb 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -30,6 +30,7 @@ class Account(Document): self.validate_mandatory() self.validate_warehouse_account() self.validate_frozen_accounts_modifier() + self.validate_balance_must_be_settings() def validate_master_name(self): if self.master_type in ('Customer', 'Supplier') or self.account_type == "Warehouse": @@ -69,6 +70,15 @@ class Account(Document): frozen_accounts_modifier not in frappe.user.get_roles(): throw(_("You are not authorized to set Frozen value")) + def validate_balance_must_be_settings(self): + from erpnext.accounts.utils import get_balance_on + account_balance = get_balance_on(self.name) + + if account_balance > 0 and self.balance_must_be == "Credit": + frappe.throw(_("Account balance already in Debit, you are not allowed to set 'Balance Must Be' as 'Credit'")) + elif account_balance < 0 and self.balance_must_be == "Debit": + frappe.throw(_("Account balance already in Credit, you are not allowed to set 'Balance Must Be' as 'Debit'")) + def convert_group_to_ledger(self): if self.check_if_child_exists(): throw(_("Account with child nodes cannot be converted to ledger"))