Account balance must be of type debit/credit
This commit is contained in:
parent
49a6f0754e
commit
53822ae9d0
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"creation": "2013-01-30 12:49:46",
|
"creation": "2013-01-30 12:49:46",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2014-03-03 17:21:07",
|
"modified": "2014-03-03 18:43:33",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -216,12 +216,11 @@
|
|||||||
"options": "[Select]"
|
"options": "[Select]"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "1",
|
|
||||||
"depends_on": "eval:doc.group_or_ledger==\"Ledger\"",
|
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "allow_negative_balance",
|
"fieldname": "balance_must_be",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Select",
|
||||||
"label": "Allow Negative Balance"
|
"label": "Balance must be",
|
||||||
|
"options": "\nDebit\nCredit"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class DocType:
|
|||||||
self.validate_account_details(adv_adj)
|
self.validate_account_details(adv_adj)
|
||||||
validate_frozen_account(self.doc.account, adv_adj)
|
validate_frozen_account(self.doc.account, adv_adj)
|
||||||
check_freezing_date(self.doc.posting_date, 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
|
# Update outstanding amt on against voucher
|
||||||
if self.doc.against_voucher and self.doc.against_voucher_type != "POS" \
|
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 +
|
frappe.throw(_("Cost Center") + ": " + self.doc.cost_center +
|
||||||
_(" does not belong to the company") + ": " + self.doc.company)
|
_(" 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:
|
if not adv_adj and account:
|
||||||
account_details = frappe.db.get_value("Account", account,
|
balance_must_be = frappe.db.get_value("Account", account, "balance_must_be")
|
||||||
["allow_negative_balance", "debit_or_credit"], as_dict=True)
|
if balance_must_be:
|
||||||
if not account_details["allow_negative_balance"]:
|
balance = frappe.db.sql("""select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||||
balance = frappe.db.sql("""select sum(debit) - sum(credit) from `tabGL Entry`
|
from `tabGL Entry` where account = %s""", account)[0][0]
|
||||||
where account = %s""", account)
|
|
||||||
balance = account_details["debit_or_credit"] == "Debit" and \
|
if (balance_must_be=="Debit" and flt(balance) < 0) or \
|
||||||
flt(balance[0][0]) or -1*flt(balance[0][0])
|
(balance_must_be=="Credit" and flt(balance) > 0):
|
||||||
|
frappe.throw("Credit" if balance_must_be=="Debit" else "Credit"
|
||||||
if flt(balance) < 0:
|
+ _(" balance is not allowed for account ") + account)
|
||||||
frappe.throw(_("Negative balance is not allowed for account ") + account)
|
|
||||||
|
|
||||||
def check_freezing_date(posting_date, adv_adj=False):
|
def check_freezing_date(posting_date, adv_adj=False):
|
||||||
"""
|
"""
|
||||||
Nobody can do GL Entries where posting date is before freezing date
|
Nobody can do GL Entries where posting date is before freezing date
|
||||||
|
|||||||
@ -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,
|
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
|
||||||
adv_adj=False, update_outstanding="Yes"):
|
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
|
check_freezing_date, update_outstanding_amt, validate_frozen_account
|
||||||
|
|
||||||
if not gl_entries:
|
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:
|
for entry in gl_entries:
|
||||||
validate_frozen_account(entry["account"], adv_adj)
|
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)
|
validate_expense_against_budget(entry)
|
||||||
|
|
||||||
if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \
|
if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \
|
||||||
|
|||||||
@ -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, '')=''""")
|
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.remove_module_home_pages
|
||||||
erpnext.patches.4_0.split_email_settings
|
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
|
||||||
|
|||||||
14
erpnext/patches/4_0/set_account_details.py
Normal file
14
erpnext/patches/4_0/set_account_details.py
Normal 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""")
|
||||||
Loading…
x
Reference in New Issue
Block a user