Account balance must be of type debit/credit

This commit is contained in:
Nabin Hait 2014-03-03 19:18:17 +05:30
parent 49a6f0754e
commit 53822ae9d0
5 changed files with 35 additions and 22 deletions

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-30 12:49:46",
"docstatus": 0,
"modified": "2014-03-03 17:21:07",
"modified": "2014-03-03 18:43:33",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -216,12 +216,11 @@
"options": "[Select]"
},
{
"default": "1",
"depends_on": "eval:doc.group_or_ledger==\"Ledger\"",
"doctype": "DocField",
"fieldname": "allow_negative_balance",
"fieldtype": "Check",
"label": "Allow Negative Balance"
"fieldname": "balance_must_be",
"fieldtype": "Select",
"label": "Balance must be",
"options": "\nDebit\nCredit"
},
{
"doctype": "DocField",

View File

@ -22,7 +22,7 @@ class DocType:
self.validate_account_details(adv_adj)
validate_frozen_account(self.doc.account, adv_adj)
check_freezing_date(self.doc.posting_date, adv_adj)
check_negative_balance(self.doc.account, adv_adj)
validate_balance_type(self.doc.account, adv_adj)
# Update outstanding amt on against voucher
if self.doc.against_voucher and self.doc.against_voucher_type != "POS" \
@ -89,19 +89,18 @@ class DocType:
frappe.throw(_("Cost Center") + ": " + self.doc.cost_center +
_(" does not belong to the company") + ": " + self.doc.company)
def check_negative_balance(account, adv_adj=False):
def validate_balance_type(account, adv_adj=False):
if not adv_adj and account:
account_details = frappe.db.get_value("Account", account,
["allow_negative_balance", "debit_or_credit"], as_dict=True)
if not account_details["allow_negative_balance"]:
balance = frappe.db.sql("""select sum(debit) - sum(credit) from `tabGL Entry`
where account = %s""", account)
balance = account_details["debit_or_credit"] == "Debit" and \
flt(balance[0][0]) or -1*flt(balance[0][0])
if flt(balance) < 0:
frappe.throw(_("Negative balance is not allowed for account ") + account)
balance_must_be = frappe.db.get_value("Account", account, "balance_must_be")
if balance_must_be:
balance = frappe.db.sql("""select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", account)[0][0]
if (balance_must_be=="Debit" and flt(balance) < 0) or \
(balance_must_be=="Credit" and flt(balance) > 0):
frappe.throw("Credit" if balance_must_be=="Debit" else "Credit"
+ _(" balance is not allowed for account ") + account)
def check_freezing_date(posting_date, adv_adj=False):
"""
Nobody can do GL Entries where posting date is before freezing date

View File

@ -103,7 +103,7 @@ def validate_account_for_auto_accounting_for_stock(gl_map):
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
adv_adj=False, update_outstanding="Yes"):
from erpnext.accounts.doctype.gl_entry.gl_entry import check_negative_balance, \
from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
check_freezing_date, update_outstanding_amt, validate_frozen_account
if not gl_entries:
@ -117,7 +117,7 @@ def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
for entry in gl_entries:
validate_frozen_account(entry["account"], adv_adj)
check_negative_balance(entry["account"], adv_adj)
validate_balance_type(entry["account"], adv_adj)
validate_expense_against_budget(entry)
if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \

View File

@ -27,4 +27,5 @@ erpnext.patches.4_0.customer_discount_to_pricing_rule
execute:frappe.db.sql("""delete from `tabWebsite Item Group` where ifnull(item_group, '')=''""")
erpnext.patches.4_0.remove_module_home_pages
erpnext.patches.4_0.split_email_settings
erpnext.patches.4_0.fix_employee_user_id
erpnext.patches.4_0.fix_employee_user_id
erpnext.patches.4_0.set_account_details

View File

@ -0,0 +1,14 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for d in (('Asset', 'Debit', 'No'), ('Liability', 'Credit', 'No'), ('Expense', 'Debit', 'Yes'),
('Income', 'Credit', 'Yes')):
frappe.db.sql("""update `tabAccount` set root_type = %s
where debit_or_credit=%s and is_pl_account=%s""", d)
frappe.db.sql("""update `tabAccount` set balance_must_be=debit_or_credit
where ifnull(allow_negative_balance, 0) = 0""")