mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 07:32:50 +00:00
patch function written for illegal cancelled entry
This commit is contained in:
@@ -21,31 +21,34 @@ class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d,dl
|
||||
|
||||
def repost(self):
|
||||
def repost(self, account = ''):
|
||||
if not self.doc.company:
|
||||
msgprint("Please select company", raise_exception=1)
|
||||
|
||||
if not in_transaction:
|
||||
sql("start transaction")
|
||||
|
||||
self.clear_account_balances()
|
||||
self.create_account_balances()
|
||||
self.update_opening()
|
||||
self.post_entries()
|
||||
self.clear_account_balances(account)
|
||||
self.create_account_balances(account)
|
||||
self.update_opening(account)
|
||||
self.post_entries(account)
|
||||
sql("commit")
|
||||
msgprint("Account balance reposted")
|
||||
|
||||
def clear_account_balances(self):
|
||||
msg_cond = account and " and account: " + account or ""
|
||||
msgprint("Account balance reposted for fiscal year: " + self.doc.name + msg_cond)
|
||||
|
||||
def clear_account_balances(self, account = ''):
|
||||
# balances clear - `tabAccount Balance` for fiscal year
|
||||
sql("update `tabAccount Balance` set opening=0, balance=0, debit=0, credit=0 where fiscal_year=%s", self.doc.name)
|
||||
cond = account and (" and account = '" + account + "'") or ''
|
||||
sql("update `tabAccount Balance` set opening=0, balance=0, debit=0, credit=0 where fiscal_year=%s %s", (self.doc.name, cond))
|
||||
|
||||
def create_account_balances(self):
|
||||
def create_account_balances(self, account = ''):
|
||||
# get periods
|
||||
period_list = self.get_period_list()
|
||||
cnt = 0
|
||||
|
||||
# get accounts
|
||||
al = sql("select name from tabAccount")
|
||||
al = account and [[account]] or sql("select name from tabAccount")
|
||||
|
||||
for a in al:
|
||||
# check
|
||||
@@ -80,9 +83,14 @@ class DocType:
|
||||
return periods
|
||||
|
||||
# ====================================================================================
|
||||
def update_opening(self):
|
||||
# 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))
|
||||
def update_opening(self, account = ''):
|
||||
"""
|
||||
set opening from last year closing
|
||||
|
||||
"""
|
||||
cond = account and (" and t2.name = '" + account + "'") or ''
|
||||
|
||||
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 %s for update" % (self.doc.past_year, self.doc.company, cond))
|
||||
|
||||
cnt = 0
|
||||
for ab in abl:
|
||||
@@ -100,10 +108,11 @@ class DocType:
|
||||
return sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", account)[0]
|
||||
|
||||
# ====================================================================================
|
||||
def post_entries(self):
|
||||
def post_entries(self, account = ''):
|
||||
sql("LOCK TABLE `tabGL Entry` WRITE")
|
||||
cond = account and (" and account = '" + account + "'") or ''
|
||||
# post each gl entry (batch or complete)
|
||||
gle = sql("select name, account, debit, credit, is_opening, posting_date from `tabGL Entry` where fiscal_year=%s and ifnull(is_cancelled,'No')='No' and company=%s", (self.doc.name, self.doc.company))
|
||||
gle = sql("select name, account, debit, credit, is_opening, posting_date from `tabGL Entry` where fiscal_year=%s and ifnull(is_cancelled,'No')='No' and company=%s %s", (self.doc.name, self.doc.company, cond))
|
||||
account_details = {}
|
||||
|
||||
cnt = 0
|
||||
@@ -153,7 +162,6 @@ class DocType:
|
||||
sql("UNLOCK TABLES")
|
||||
|
||||
|
||||
|
||||
# Clear PV/RV outstanding
|
||||
# ====================================================================================
|
||||
def clear_outstanding(self):
|
||||
|
||||
@@ -8,7 +8,6 @@ from webnotes.model.doclist import getlist, copy_doclist
|
||||
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
||||
from webnotes import session, form, is_testing, msgprint, errprint
|
||||
|
||||
set = webnotes.conn.set
|
||||
sql = webnotes.conn.sql
|
||||
get_value = webnotes.conn.get_value
|
||||
in_transaction = webnotes.conn.in_transaction
|
||||
@@ -400,3 +399,31 @@ In Account := %s User := %s has Repaired Outstanding Amount For %s : %s and foll
|
||||
sendmail(['support@iwebnotes.com'], subject='Repair Outstanding Amount', parts = [('text/plain', email_msg)])
|
||||
# Acknowledge User
|
||||
msgprint(cstr(voucher_obj.doc.doctype) + " : " + cstr(voucher_obj.doc.name) + " has been checked" + cstr(msg and " and repaired successfully." or ". No changes Found."))
|
||||
|
||||
|
||||
#==============================================================
|
||||
def repost_illegal_cancelled(self, after_date='2011-01-01'):
|
||||
"""
|
||||
Find vouchers that are not cancelled correctly and repost them
|
||||
"""
|
||||
vl = sql("""
|
||||
select voucher_type, voucher_no, account, sum(debit) as sum_debit, sum(credit) as sum_credit
|
||||
from `tabGL Entry`
|
||||
where is_cancelled='Yes' and creation > %s
|
||||
group by voucher_type, voucher_no, account
|
||||
""", after_date, as_dict=1)
|
||||
|
||||
ac_list = []
|
||||
for v in vl:
|
||||
if v['sum_debit'] != 0 or v['sum_credit'] != 0:
|
||||
ac_list.append(v['account'])
|
||||
|
||||
fy_list = 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))
|
||||
or year_start_date > %s
|
||||
order by year_start_date ASC""", (after_date, after_date))
|
||||
|
||||
for fy in fy_list:
|
||||
fy_obj = get_obj('Fiscal Year', fy[0])
|
||||
for a in set(ac_list):
|
||||
fy_obj.repost(a)
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2011-07-07 18:05:53',
|
||||
'creation': '2011-07-08 13:30:05',
|
||||
'docstatus': 0,
|
||||
'modified': '2011-07-07 18:51:19',
|
||||
'modified': '2011-07-08 13:30:05',
|
||||
'modified_by': 'Administrator',
|
||||
'owner': 'Guest'
|
||||
'owner': 'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
|
||||
@@ -44,7 +44,7 @@ class DocType:
|
||||
# =============================================================================
|
||||
def get_bin_qty(self, wh, item):
|
||||
# get actual_qty
|
||||
act_qty = sql("select ifnull(actual_qty, 0) from `tabBin` where warehouse = '%s' and item_code = '%s'" % (wh, item))
|
||||
act_qty = sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and ifnull(is_cancelled, 'No') = 'No'" % (wh, item))
|
||||
act_qty = act_qty and flt(act_qty[0][0]) or 0
|
||||
|
||||
# get indented_qty
|
||||
@@ -120,6 +120,17 @@ class DocType:
|
||||
self.repair_bin(bin[0])
|
||||
|
||||
# =============================================================================
|
||||
def repair_bins_for_illegal_cancelled(self, after_date = '2011-01-01'):
|
||||
bins = sql("select name from tabBin where modified >= %s", after_date)
|
||||
cnt = 0
|
||||
for bin in bins:
|
||||
if cnt % 20 == 0:
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
cnt += 1
|
||||
|
||||
self.repair_bin(bin[0])
|
||||
# =============================================================================
|
||||
def repair_opening_bal(self, d, acc_obj, past_yr, fiscal_yr):
|
||||
# check opening balance
|
||||
opbal = sql("select balance from `tabAccount Balance` where account=%s and period = %s", (acc_obj.doc.name, past_yr))
|
||||
|
||||
Reference in New Issue
Block a user