fix in get_balance_on for a date which does not fall within any fiscal year
This commit is contained in:
parent
037c2570b6
commit
d69b32e856
@ -150,7 +150,7 @@ cur_frm.cscript.account = function(doc,dt,dn) {
|
|||||||
args: {account: d.account, date: doc.posting_date},
|
args: {account: d.account, date: doc.posting_date},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
d.balance = fmt_money(r.message);
|
d.balance = fmt_money(r.message);
|
||||||
refresh_field('balance',d.name,'entries');
|
refresh_field('balance', d.name, 'entries');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,6 @@ else:
|
|||||||
from_date = filter_values['posting_date']
|
from_date = filter_values['posting_date']
|
||||||
to_date = filter_values['posting_date1']
|
to_date = filter_values['posting_date1']
|
||||||
|
|
||||||
from_date_year = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",from_date)
|
|
||||||
if not from_date_year:
|
|
||||||
msgprint("From Date is out of range. Please check.", raise_exception=1)
|
|
||||||
else:
|
|
||||||
from_date_year = from_date_year[0][0]
|
|
||||||
#to_date_year = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",to_date)[0][0]
|
|
||||||
|
|
||||||
|
|
||||||
# define columns
|
# define columns
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
col = []
|
col = []
|
||||||
|
@ -19,7 +19,9 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import nowdate
|
from webnotes.utils import nowdate
|
||||||
|
|
||||||
def get_fiscal_year(date):
|
class FiscalYearError(webnotes.ValidationError): pass
|
||||||
|
|
||||||
|
def get_fiscal_year(date, verbose=1):
|
||||||
from webnotes.utils import formatdate
|
from webnotes.utils import formatdate
|
||||||
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
||||||
fy = webnotes.conn.sql("""select name, year_start_date,
|
fy = webnotes.conn.sql("""select name, year_start_date,
|
||||||
@ -30,8 +32,9 @@ def get_fiscal_year(date):
|
|||||||
(date, date))
|
(date, date))
|
||||||
|
|
||||||
if not fy:
|
if not fy:
|
||||||
webnotes.msgprint("""%s not in any Fiscal Year""" % formatdate(date),
|
error_msg = """%s not in any Fiscal Year""" % formatdate(date)
|
||||||
raise_exception=1)
|
if verbose: webnotes.msgprint(error_msg)
|
||||||
|
raise FiscalYearError, error_msg
|
||||||
|
|
||||||
return fy[0]
|
return fy[0]
|
||||||
|
|
||||||
@ -40,18 +43,34 @@ def get_balance_on(account=None, date=None):
|
|||||||
if not account and webnotes.form_dict.get("account"):
|
if not account and webnotes.form_dict.get("account"):
|
||||||
account = webnotes.form_dict.get("account")
|
account = webnotes.form_dict.get("account")
|
||||||
date = webnotes.form_dict.get("date")
|
date = webnotes.form_dict.get("date")
|
||||||
|
|
||||||
cond = []
|
cond = []
|
||||||
if date:
|
if date:
|
||||||
cond.append("posting_date <= '%s'" % date)
|
cond.append("posting_date <= '%s'" % date)
|
||||||
|
else:
|
||||||
|
# get balance of all entries that exist
|
||||||
|
date = nowdate()
|
||||||
|
|
||||||
|
try:
|
||||||
|
year_start_date = get_fiscal_year(date, verbose=0)[1]
|
||||||
|
except FiscalYearError, e:
|
||||||
|
from webnotes.utils import getdate
|
||||||
|
if getdate(date) > getdate(nowdate()):
|
||||||
|
# if fiscal year not found and the date is greater than today
|
||||||
|
# get fiscal year for today's date and its corresponding year start date
|
||||||
|
year_start_date = get_fiscal_year(nowdate(), verbose=1)[1]
|
||||||
|
else:
|
||||||
|
# this indicates that it is a date older than any existing fiscal year.
|
||||||
|
# hence, assuming balance as 0.0
|
||||||
|
return 0.0
|
||||||
|
|
||||||
acc = webnotes.conn.get_value('Account', account, \
|
acc = webnotes.conn.get_value('Account', account, \
|
||||||
['lft', 'rgt', 'debit_or_credit', 'is_pl_account', 'group_or_ledger'], as_dict=1)
|
['lft', 'rgt', 'debit_or_credit', 'is_pl_account', 'group_or_ledger'], as_dict=1)
|
||||||
|
|
||||||
# for pl accounts, get balance within a fiscal year
|
# for pl accounts, get balance within a fiscal year
|
||||||
if acc.is_pl_account == 'Yes':
|
if acc.is_pl_account == 'Yes':
|
||||||
cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" % \
|
cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \
|
||||||
get_fiscal_year(date or nowdate())[1])
|
% year_start_date)
|
||||||
|
|
||||||
# different filter for group and ledger - improved performance
|
# different filter for group and ledger - improved performance
|
||||||
if acc.group_or_ledger=="Group":
|
if acc.group_or_ledger=="Group":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user