From b4418a4997691efbd4db6a91cc7e2ac7dc346eea Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 22 Aug 2013 14:38:46 +0530 Subject: [PATCH] [minor] budget cleanup --- accounts/utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/accounts/utils.py b/accounts/utils.py index bb1e5d9b6b..d91c4db62e 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -372,3 +372,31 @@ def get_stock_and_account_difference(warehouse_list=None): difference.setdefault(account, flt(stock_value) - flt(account_balance)) return difference + + +def validate_expense_against_budget(args): + args = webnotes._dict(args) + if webnotes.conn.get_value("Account", {"name": args.account, "is_pl_account": "Yes", + "debit_or_credit": "Debit"}): + budget = webnotes.conn.sql(""" + select bd.budget_allocated, cc.distribution_id + from `tabCost Center` cc, `tabBudget Detail` bd + where cc.name=bd.parent and cc.name=%s and account=%s and bd.fiscal_year=%s + """, (args.cost_center, args.account, args.fiscal_year), as_dict=True) + + if budget and budget[0].budget_allocated: + action = webnotes.conn.get_value("Company", args.company, + ["yearly_bgt_flag", "monthly_bgt_flag"]) + + args["month_end_date"] = webnotes.conn.sql("select LAST_DAY(%s)", args.posting_date) + + expense_upto_date = get_actual_expense(args) + +def get_actual_expense(args): + return webnotes.conn.sql(""" + select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) + from `tabGL Entry` + where account=%(account)s and cost_center=%(cost_center)s + and posting_date<=%(month_end_date)s + and fiscal_year=%(fiscal_year)s and company=%(company)s + """, (args))[0][0] \ No newline at end of file