Update future year balances at the time of tranaction and acc bal reposting patch
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.js b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js
new file mode 100644
index 0000000..fdc25fe
--- /dev/null
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.js
@@ -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']);
+}
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
index 74b90cc..bf67896 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
@@ -27,10 +27,10 @@
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 @@
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 @@
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])
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index c45e162..b905afa 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -135,12 +135,9 @@
# 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 @@
,'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 @@
%(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)
#-----------------------------
diff --git a/erpnext/patches/before_jan_2012/repost_account_bal.py b/erpnext/patches/before_jan_2012/repost_account_bal.py
index 34edc04..7ca8b39 100644
--- a/erpnext/patches/before_jan_2012/repost_account_bal.py
+++ b/erpnext/patches/before_jan_2012/repost_account_bal.py
@@ -4,13 +4,6 @@
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 @@
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', '')
diff --git a/erpnext/production/doctype/bill_of_materials/bill_of_materials.py b/erpnext/production/doctype/bill_of_materials/bill_of_materials.py
index 1177425..decb9fe 100644
--- a/erpnext/production/doctype/bill_of_materials/bill_of_materials.py
+++ b/erpnext/production/doctype/bill_of_materials/bill_of_materials.py
@@ -268,7 +268,7 @@
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)])