Update future year balances at the time of tranaction and acc bal reposting patch
This commit is contained in:
parent
72129a8587
commit
0cde984dc5
7
erpnext/accounts/doctype/fiscal_year/fiscal_year.js
Normal file
7
erpnext/accounts/doctype/fiscal_year/fiscal_year.js
Normal file
@ -0,0 +1,7 @@
|
||||
cur_frm.cscript.refresh = function(doc, dt, dn) {
|
||||
if (doc.__islocal) {
|
||||
hide_field(['Repost Account Balances', 'Repost Voucher Outstanding']);
|
||||
set_multiple(dt, dn, {'is_fiscal_year_closed': 'No'});
|
||||
}
|
||||
else unhide_field(['Repost Account Balances', 'Repost Voucher Outstanding']);
|
||||
}
|
@ -27,10 +27,10 @@ class DocType:
|
||||
|
||||
if not in_transaction:
|
||||
sql("start transaction")
|
||||
|
||||
|
||||
self.clear_account_balances()
|
||||
self.create_account_balances()
|
||||
self.update_opening()
|
||||
self.update_opening(self.doc.company)
|
||||
self.post_entries()
|
||||
sql("commit")
|
||||
|
||||
@ -81,17 +81,17 @@ class DocType:
|
||||
return periods
|
||||
|
||||
# ====================================================================================
|
||||
def update_opening(self):
|
||||
def update_opening(self, company):
|
||||
"""
|
||||
set opening from last year closing
|
||||
|
||||
"""
|
||||
|
||||
abl = sql("select t1.account, t1.balance from `tabAccount Balance` t1, tabAccount t2 where t1.period= '%s' and t2.company= '%s' and ifnull(t2.is_pl_account, 'No') = 'No' and t1.account = t2.name for update" % (self.doc.past_year, self.doc.company))
|
||||
abl = sql("select t1.account, t1.balance from `tabAccount Balance` t1, tabAccount t2 where t1.period= '%s' and t2.company= '%s' and ifnull(t2.is_pl_account, 'No') = 'No' and t1.account = t2.name for update" % (self.doc.past_year, company))
|
||||
|
||||
cnt = 0
|
||||
for ab in abl:
|
||||
if cnt % 100 == 0:
|
||||
if cnt % 100 == 0:
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
|
||||
@ -184,10 +184,19 @@ class DocType:
|
||||
def create_periods(self):
|
||||
get_obj('Period Control').generate_periods(self.doc.name)
|
||||
|
||||
def validate(self):
|
||||
if sql("select name from `tabFiscal Year` where year_start_date < %s", self.doc.year_start_date) and not self.doc.past_year:
|
||||
msgprint("Please enter Past Year", raise_exception=1)
|
||||
|
||||
if not self.doc.is_fiscal_year_closed:
|
||||
self.doc.is_fiscal_year_closed = 'No'
|
||||
|
||||
|
||||
# on update
|
||||
def on_update(self):
|
||||
if not self.doc.is_fiscal_year_closed:
|
||||
self.is_fiscal_year_closed = 'No'
|
||||
self.doc.save()
|
||||
self.create_periods()
|
||||
self.create_account_balances()
|
||||
|
||||
if self.doc.fields.get('localname', '')[:15] == 'New Fiscal Year':
|
||||
for d in sql("select name from tabCompany"):
|
||||
self.update_opening(d[0])
|
||||
|
@ -135,12 +135,9 @@ class DocType:
|
||||
# amount to debit
|
||||
amt = flt(self.doc.debit) - flt(self.doc.credit)
|
||||
if det[0][2] == 'Credit': amt = -amt
|
||||
if cancel:
|
||||
debit = -1 * flt(self.doc.credit)
|
||||
credit = -1 * flt(self.doc.debit)
|
||||
else:
|
||||
debit = flt(self.doc.debit)
|
||||
credit = flt(self.doc.credit)
|
||||
|
||||
debit = cancel and -1 * flt(self.doc.credit) or flt(self.doc.debit)
|
||||
credit = cancel and -1 * flt(self.doc.debit) or flt(self.doc.credit)
|
||||
|
||||
self.create_new_balances(det)
|
||||
|
||||
@ -158,6 +155,7 @@ class DocType:
|
||||
,'fiscal_year': self.doc.fiscal_year
|
||||
}
|
||||
|
||||
# Update account balance for current year
|
||||
sql("""update `tabAccount Balance` ab, `tabAccount` a
|
||||
set
|
||||
ab.debit = ifnull(ab.debit,0) + %(debit)s
|
||||
@ -171,6 +169,34 @@ class DocType:
|
||||
%(end_date_condition)s
|
||||
and ab.fiscal_year = '%(fiscal_year)s' """ % p)
|
||||
|
||||
# Future year balances
|
||||
# Update opening only where period_type is Year
|
||||
sql("""update `tabAccount Balance` ab, `tabAccount` a, `tabFiscal Year` fy
|
||||
set
|
||||
ab.opening = ifnull(ab.opening,0) + %(diff)s
|
||||
where
|
||||
a.lft <= %(lft)s
|
||||
and a.rgt >= %(rgt)s
|
||||
and ab.account = a.name
|
||||
and ifnull(a.is_pl_account, 'No') = 'No'
|
||||
and ab.period = ab.fiscal_year
|
||||
and fy.name = ab.fiscal_year
|
||||
and fy.year_start_date > %(posting_date)s""" % p)
|
||||
|
||||
# Update balance for all period for future years
|
||||
sql("""update `tabAccount Balance` ab, `tabAccount` a, `tabFiscal Year` fy
|
||||
set
|
||||
ab.balance = ifnull(ab.balance,0) + %(diff)s
|
||||
where
|
||||
a.lft <= %(lft)s
|
||||
and a.rgt >= %(rgt)s
|
||||
and ab.account = a.name
|
||||
and ifnull(a.is_pl_account, 'No') = 'No'
|
||||
and fy.name = ab.fiscal_year
|
||||
and fy.year_start_date > %(posting_date)s""" % p)
|
||||
|
||||
|
||||
|
||||
|
||||
# Get periods(month and year)
|
||||
#-----------------------------
|
||||
|
@ -4,13 +4,6 @@ def execute():
|
||||
sql = webnotes.conn.sql
|
||||
from webnotes.model.code import get_obj
|
||||
|
||||
# stop session
|
||||
webnotes.conn.set_global('__session_status', 'stop')
|
||||
webnotes.conn.set_global('__session_status_message', 'Patch is running in background. \nPlease wait until it completed...\n')
|
||||
|
||||
webnotes.conn.commit()
|
||||
webnotes.conn.begin()
|
||||
|
||||
# repost
|
||||
comp = sql("select name from tabCompany where docstatus!=2")
|
||||
fy = sql("select name from `tabFiscal Year` order by year_start_date asc")
|
||||
@ -21,11 +14,9 @@ def execute():
|
||||
fy_obj.doc.past_year = prev_fy
|
||||
fy_obj.doc.company = c[0]
|
||||
fy_obj.doc.save()
|
||||
|
||||
fy_obj = get_obj('Fiscal Year', f[0])
|
||||
fy_obj.repost()
|
||||
prev_fy = f[0]
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
|
||||
# free session
|
||||
webnotes.conn.set_global('__session_status', '')
|
||||
webnotes.conn.set_global('__session_status_message', '')
|
||||
|
@ -268,7 +268,7 @@ class DocType:
|
||||
|
||||
def check_if_item_repeated(self, item, op, check_list):
|
||||
if [cstr(item), cstr(op)] in check_list:
|
||||
msgprint("Item %s has been entered twice against same operation" % d.item_code, raise_exception = 1)
|
||||
msgprint("Item %s has been entered twice against same operation" % item, raise_exception = 1)
|
||||
else:
|
||||
check_list.append([cstr(item), cstr(op)])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user