[fix] credit limit validation

This commit is contained in:
Nabin Hait 2013-11-14 18:37:33 +05:30
parent 49f2bafa0f
commit 155232e04e
5 changed files with 17 additions and 42 deletions

View File

@ -32,16 +32,6 @@ class DocType:
self.validate_root_details()
self.validate_mandatory()
self.validate_warehouse_account()
if not self.doc.parent_account:
self.doc.parent_account = ''
def validate(self):
self.validate_master_name()
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
self.validate_frozen_accounts_modifier()
if not self.doc.parent_account:
@ -177,24 +167,24 @@ class DocType:
in webnotes.user.get_roles():
return 1
def check_credit_limit(self, account, company, tot_outstanding):
def check_credit_limit(self, total_outstanding):
# Get credit limit
credit_limit_from = 'Customer'
cr_limit = sql("""select t1.credit_limit from tabCustomer t1, `tabAccount` t2
where t2.name=%s and t1.name = t2.master_name""", account)
where t2.name=%s and t1.name = t2.master_name""", self.doc.name)
credit_limit = cr_limit and flt(cr_limit[0][0]) or 0
if not credit_limit:
credit_limit = webnotes.conn.get_value('Company', company, 'credit_limit')
credit_limit_from = 'global settings in the Company'
credit_limit = webnotes.conn.get_value('Company', self.doc.company, 'credit_limit')
credit_limit_from = 'Company'
# If outstanding greater than credit limit and not authorized person raise exception
if credit_limit > 0 and flt(tot_outstanding) > credit_limit \
if credit_limit > 0 and flt(total_outstanding) > credit_limit \
and not self.get_authorized_user():
msgprint("""Total Outstanding amount (%s) for <b>%s</b> can not be \
greater than credit limit (%s). To change your credit limit settings, \
please update the <b>%s</b>""" % (fmt_money(tot_outstanding),
account, fmt_money(credit_limit), credit_limit_from), raise_exception=1)
please update in the <b>%s</b> master""" % (fmt_money(total_outstanding),
self.doc.name, fmt_money(credit_limit), credit_limit_from), raise_exception=1)
def validate_trash(self):
"""checks gl entries and if child exists"""

View File

@ -16,7 +16,6 @@ class DocType:
self.check_mandatory()
self.pl_must_have_cost_center()
self.validate_posting_date()
self.check_credit_limit()
self.check_pl_account()
self.validate_cost_center()
@ -55,21 +54,6 @@ class DocType:
from accounts.utils import validate_fiscal_year
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, "Posting Date")
def check_credit_limit(self):
master_type, master_name = webnotes.conn.get_value("Account",
self.doc.account, ["master_type", "master_name"])
tot_outstanding = 0 #needed when there is no GL Entry in the system for that acc head
if (self.doc.voucher_type=='Journal Voucher' or self.doc.voucher_type=='Sales Invoice') \
and (master_type =='Customer' and master_name):
dbcr = webnotes.conn.sql("""select sum(debit), sum(credit) from `tabGL Entry`
where account = %s""", self.doc.account)
if dbcr:
tot_outstanding = flt(dbcr[0][0]) - flt(dbcr[0][1]) + \
flt(self.doc.debit) - flt(self.doc.credit)
get_obj('Account',self.doc.account).check_credit_limit(self.doc.account,
self.doc.company, tot_outstanding)
def check_pl_account(self):
if self.doc.is_opening=='Yes' and \
webnotes.conn.get_value("Account", self.doc.account, "is_pl_account") == "Yes":

View File

@ -44,6 +44,7 @@ class DocType(AccountsController):
self.check_credit_days()
self.check_account_against_entries()
self.make_gl_entries()
self.check_credit_limit()
def on_cancel(self):
from accounts.utils import remove_against_link_from_jv
@ -259,6 +260,13 @@ class DocType(AccountsController):
)
if gl_map:
make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
def check_credit_limit(self):
for d in self.doclist.get({"parentfield": "entries"}):
master_type, master_name = webnotes.conn.get_value("Account", d.account,
["master_type", "master_name"])
if master_type == "Customer" and master_name:
super(DocType, self).check_credit_limit(d.account)
def get_outstanding(self, args):
args = eval(args)

View File

@ -16,8 +16,6 @@ def execute(filters=None):
period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"])
cam_map = get_costcenter_account_month_map(filters)
precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
data = []
for cost_center, cost_center_items in cam_map.items():

View File

@ -9,9 +9,6 @@ from webnotes.model.doc import addchild
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint, _
from setup.utils import get_company_currency
get_value = webnotes.conn.get_value
from utilities.transaction_base import TransactionBase
@ -295,14 +292,12 @@ class DocType(TransactionBase):
def check_credit(self,obj,grand_total):
acc_head = webnotes.conn.sql("select name from `tabAccount` where company = '%s' and master_name = '%s'"%(obj.doc.company, obj.doc.customer))
if acc_head:
tot_outstanding = 0
dbcr = webnotes.conn.sql("""select sum(debit), sum(credit) from `tabGL Entry`
where account = %s""", acc_head[0][0])
if dbcr:
tot_outstanding = flt(dbcr[0][0])-flt(dbcr[0][1])
tot_outstanding = flt(dbcr[0][0])-flt(dbcr[0][1]) if dbcr else 0
exact_outstanding = flt(tot_outstanding) + flt(grand_total)
get_obj('Account',acc_head[0][0]).check_credit_limit(acc_head[0][0], obj.doc.company, exact_outstanding)
get_obj('Account',acc_head[0][0]).check_credit_limit(exact_outstanding)
def get_prevdoc_date(self, obj):
for d in getlist(obj.doclist, obj.fname):