[cleanup] [accounts] delete gl entries on cancellation of accounting transactions

This commit is contained in:
Nabin Hait 2013-08-21 17:47:11 +05:30
parent 4af17a88b0
commit 9b09c95d83
19 changed files with 156 additions and 180 deletions

View File

@ -98,9 +98,7 @@ class DocType:
# Check if any previous balance exists
def check_gle_exists(self):
exists = sql("""select name from `tabGL Entry` where account = %s
and ifnull(is_cancelled, 'No') = 'No'""", self.doc.name)
return exists and exists[0][0] or ''
return webnotes.conn.get_value("GL Entry", {"account": self.doc.name})
def check_if_child_exists(self):
return sql("""select name from `tabAccount` where parent_account = %s
@ -173,10 +171,6 @@ class DocType:
self.validate_trash()
self.update_nsm_model()
# delete all cancelled gl entry of this account
sql("""delete from `tabGL Entry` where account = %s and
ifnull(is_cancelled, 'No') = 'Yes'""", self.doc.name)
def on_rename(self, new, old, merge=False):
company_abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
parts = new.split(" - ")

View File

@ -19,6 +19,8 @@ def make_test_records(verbose):
["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Service Tax", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Reserves and Surplus", "Current Liabilities - _TC", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],

View File

@ -46,8 +46,7 @@ class DocType(DocTypeNestedSet):
return 1
def check_gle_exists(self):
return webnotes.conn.sql("select name from `tabGL Entry` where cost_center = %s and \
ifnull(is_cancelled, 'No') = 'No'", (self.doc.name))
return webnotes.conn.get_value("GL Entry", {"cost_center": self.doc.name})
def check_if_child_exists(self):
return webnotes.conn.sql("select name from `tabCost Center` where \

View File

@ -7,56 +7,53 @@ import webnotes
from webnotes.utils import flt, fmt_money, getdate
from webnotes.model.code import get_obj
from webnotes import msgprint, _
sql = webnotes.conn.sql
class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d, dl
def validate(self): # not called on cancel
def validate(self):
self.check_mandatory()
self.pl_must_have_cost_center()
self.validate_posting_date()
self.doc.is_cancelled = 'No' # will be reset by GL Control if cancelled
self.check_credit_limit()
self.check_pl_account()
def on_update(self, adv_adj, cancel, update_outstanding = 'Yes'):
def on_update(self, adv_adj, update_outstanding = 'Yes'):
self.validate_account_details(adv_adj)
self.validate_cost_center()
self.check_freezing_date(adv_adj)
self.check_negative_balance(adv_adj)
validate_freezed_account(self.doc.account, adv_adj)
check_freezing_date(self.doc.posting_date, adv_adj)
check_negative_balance(self.doc.account, adv_adj)
# Update outstanding amt on against voucher
if self.doc.against_voucher and self.doc.against_voucher_type != "POS" \
and update_outstanding == 'Yes':
self.update_outstanding_amt()
update_outstanding_amt(self.doc.account, self.doc.against_voucher_type,
self.doc.against_voucher)
def check_mandatory(self):
mandatory = ['account','remarks','voucher_type','voucher_no','fiscal_year','company']
for k in mandatory:
if not self.doc.fields.get(k):
msgprint(k + _(" is mandatory for GL Entry"), raise_exception=1)
webnotes.throw(k + _(" is mandatory for GL Entry"))
# Zero value transaction is not allowed
if not (flt(self.doc.debit) or flt(self.doc.credit)):
msgprint(_("GL Entry: Debit or Credit amount is mandatory for ") + self.doc.account,
raise_exception=1)
webnotes.throw(_("GL Entry: Debit or Credit amount is mandatory for ") +
self.doc.account)
def pl_must_have_cost_center(self):
if webnotes.conn.get_value("Account", self.doc.account, "is_pl_account") == "Yes":
if not self.doc.cost_center and self.doc.voucher_type != 'Period Closing Voucher':
msgprint(_("Cost Center must be specified for PL Account: ") + self.doc.account,
raise_exception=1)
else:
if self.doc.cost_center:
self.doc.cost_center = ""
webnotes.throw(_("Cost Center must be specified for PL Account: ") +
self.doc.account)
elif self.doc.cost_center:
self.doc.cost_center = None
def validate_posting_date(self):
from accounts.utils import validate_fiscal_year
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, "Posting Date")
def check_credit_limit(self):
master_type, master_name = webnotes.conn.get_value("Account",
@ -65,8 +62,8 @@ class DocType:
tot_outstanding = 0 #needed when there is no GL Entry in the system for that acc head
if (self.doc.voucher_type=='Journal Voucher' or self.doc.voucher_type=='Sales Invoice') \
and (master_type =='Customer' and master_name):
dbcr = sql("""select sum(debit), sum(credit) from `tabGL Entry`
where account = '%s' and is_cancelled='No'""" % self.doc.account)
dbcr = webnotes.conn.sql("""select sum(debit), sum(credit) from `tabGL Entry`
where account = %s""", self.doc.account)
if dbcr:
tot_outstanding = flt(dbcr[0][0]) - flt(dbcr[0][1]) + \
flt(self.doc.debit) - flt(self.doc.credit)
@ -76,30 +73,23 @@ class DocType:
def check_pl_account(self):
if self.doc.is_opening=='Yes' and \
webnotes.conn.get_value("Account", self.doc.account, "is_pl_account") == "Yes":
msgprint(_("For opening balance entry account can not be a PL account"),
raise_exception=1)
webnotes.throw(_("For opening balance entry account can not be a PL account"))
def validate_account_details(self, adv_adj):
"""Account must be ledger, active and not freezed"""
ret = sql("""select group_or_ledger, docstatus, freeze_account, company
from tabAccount where name=%s""", self.doc.account, as_dict=1)
ret = webnotes.conn.sql("""select group_or_ledger, docstatus, company
from tabAccount where name=%s""", self.doc.account, as_dict=1)[0]
if ret and ret[0]["group_or_ledger"]=='Group':
msgprint(_("Account") + ": " + self.doc.account + _(" is not a ledger"), raise_exception=1)
if ret.group_or_ledger=='Group':
webnotes.throw(_("Account") + ": " + self.doc.account + _(" is not a ledger"))
if ret and ret[0]["docstatus"]==2:
msgprint(_("Account") + ": " + self.doc.account + _(" is not active"), raise_exception=1)
if ret.docstatus==2:
webnotes.throw(_("Account") + ": " + self.doc.account + _(" is not active"))
# Account has been freezed for other users except account manager
if ret and ret[0]["freeze_account"]== 'Yes' and not adv_adj \
and not 'Accounts Manager' in webnotes.user.get_roles():
msgprint(_("Account") + ": " + self.doc.account + _(" has been freezed. \
Only Accounts Manager can do transaction against this account"), raise_exception=1)
if self.doc.is_cancelled in ("No", None) and ret and ret[0]["company"] != self.doc.company:
msgprint(_("Account") + ": " + self.doc.account + _(" does not belong to the company") \
+ ": " + self.doc.company, raise_exception=1)
if ret.company != self.doc.company:
webnotes.throw(_("Account") + ": " + self.doc.account +
_(" does not belong to the company") + ": " + self.doc.company)
def validate_cost_center(self):
if not hasattr(self, "cost_center_company"):
@ -107,70 +97,76 @@ class DocType:
def _get_cost_center_company():
if not self.cost_center_company.get(self.doc.cost_center):
self.cost_center_company[self.doc.cost_center] = webnotes.conn.get_value("Cost Center",
self.doc.cost_center, "company")
self.cost_center_company[self.doc.cost_center] = webnotes.conn.get_value(
"Cost Center", self.doc.cost_center, "company")
return self.cost_center_company[self.doc.cost_center]
if self.doc.is_cancelled in ("No", None) and \
self.doc.cost_center and _get_cost_center_company() != self.doc.company:
msgprint(_("Cost Center") + ": " + self.doc.cost_center \
+ _(" does not belong to the company") + ": " + self.doc.company, raise_exception=True)
def check_freezing_date(self, adv_adj):
"""
Nobody can do GL Entries where posting date is before freezing date
except authorized person
"""
if not adv_adj:
acc_frozen_upto = webnotes.conn.get_value('Accounts Settings', None, 'acc_frozen_upto')
if acc_frozen_upto:
bde_auth_role = webnotes.conn.get_value( 'Accounts Settings', None,'bde_auth_role')
if getdate(self.doc.posting_date) <= getdate(acc_frozen_upto) \
and not bde_auth_role in webnotes.user.get_roles():
msgprint(_("You are not authorized to do/modify back dated entries before ") +
getdate(acc_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
if self.doc.cost_center and _get_cost_center_company() != self.doc.company:
webnotes.throw(_("Cost Center") + ": " + self.doc.cost_center +
_(" does not belong to the company") + ": " + self.doc.company)
def check_negative_balance(self, adv_adj):
if not adv_adj:
account = webnotes.conn.get_value("Account", self.doc.account,
["allow_negative_balance", "debit_or_credit"], as_dict=True)
if not account["allow_negative_balance"]:
balance = webnotes.conn.sql("""select sum(debit) - sum(credit) from `tabGL Entry`
where account = %s and ifnull(is_cancelled, 'No') = 'No'""", self.doc.account)
balance = account["debit_or_credit"] == "Debit" and \
flt(balance[0][0]) or -1*flt(balance[0][0])
if flt(balance) < 0:
msgprint(_("Negative balance is not allowed for account ") + self.doc.account,
raise_exception=1)
def check_negative_balance(account, adv_adj=False):
if not adv_adj:
account_details = webnotes.conn.get_value("Account", account,
["allow_negative_balance", "debit_or_credit"], as_dict=True)
if not account_details["allow_negative_balance"]:
balance = webnotes.conn.sql("""select sum(debit) - sum(credit) from `tabGL Entry`
where account = %s""", account)
balance = account_details["debit_or_credit"] == "Debit" and \
flt(balance[0][0]) or -1*flt(balance[0][0])
if flt(balance) < 0:
webnotes.throw(_("Negative balance is not allowed for account ") + self.doc.account)
def update_outstanding_amt(self):
# get final outstanding amt
bal = flt(sql("""select sum(debit) - sum(credit) from `tabGL Entry`
where against_voucher=%s and against_voucher_type=%s and account = %s
and ifnull(is_cancelled,'No') = 'No'""", (self.doc.against_voucher,
self.doc.against_voucher_type, self.doc.account))[0][0] or 0.0)
def check_freezing_date(posting_date, adv_adj=False):
"""
Nobody can do GL Entries where posting date is before freezing date
except authorized person
"""
if not adv_adj:
acc_frozen_upto = webnotes.conn.get_value('Accounts Settings', None, 'acc_frozen_upto')
if acc_frozen_upto:
bde_auth_role = webnotes.conn.get_value( 'Accounts Settings', None,'bde_auth_role')
if getdate(posting_date) <= getdate(acc_frozen_upto) \
and not bde_auth_role in webnotes.user.get_roles():
webnotes.throw(_("You are not authorized to do/modify back dated entries before ")
+ getdate(acc_frozen_upto).strftime('%d-%m-%Y'))
if self.doc.against_voucher_type == 'Purchase Invoice':
def update_outstanding_amt(account, against_voucher_type, against_voucher, on_cancel=False):
# get final outstanding amt
bal = flt(webnotes.conn.sql("""select sum(debit) - sum(credit) from `tabGL Entry`
where against_voucher_type=%s and against_voucher=%s and account = %s""",
(against_voucher_type, against_voucher, account))[0][0] or 0.0)
if against_voucher_type == 'Purchase Invoice':
bal = -bal
elif against_voucher_type == "Journal Voucher":
against_voucher_amount = flt(webnotes.conn.sql("""select sum(debit) - sum(credit)
from `tabGL Entry` where voucher_type = 'Journal Voucher' and voucher_no = %s
and account = %s""", (against_voucher, account))[0][0])
bal = against_voucher_amount + bal
if against_voucher_amount < 0:
bal = -bal
elif self.doc.against_voucher_type == "Journal Voucher":
against_voucher_amount = flt(webnotes.conn.sql("""select sum(debit) - sum(credit)
from `tabGL Entry` where voucher_type = 'Journal Voucher' and voucher_no = %s
and account = %s""", (self.doc.against_voucher, self.doc.account))[0][0])
# Validation : Outstanding can not be negative
if bal < 0 and not on_cancel:
webnotes.throw(_("Outstanding for Voucher ") + gainst_voucher + _(" will become ") +
fmt_money(bal) + _(". Outstanding cannot be less than zero. \
Please match exact outstanding."))
# Update outstanding amt on against voucher
if against_voucher_type in ["Sales Invoice", "Purchase Invoice"]:
webnotes.conn.sql("update `tab%s` set outstanding_amount=%s where name='%s'" %
(against_voucher_type, bal, against_voucher))
bal = against_voucher_amount + bal
if against_voucher_amount < 0:
bal = -bal
# Validation : Outstanding can not be negative
if bal < 0 and self.doc.is_cancelled == 'No':
msgprint(_("Outstanding for Voucher ") + self.doc.against_voucher +
_(" will become ") + fmt_money(bal) + _(". Outstanding cannot be less than zero. \
Please match exact outstanding."), raise_exception=1)
# Update outstanding amt on against voucher
if self.doc.against_voucher_type in ["Sales Invoice", "Purchase Invoice"]:
sql("update `tab%s` set outstanding_amount=%s where name='%s'"%
(self.doc.against_voucher_type, bal, self.doc.against_voucher))
def validate_freezed_account(account, adv_adj=False):
"""Account has been freezed for other users except account manager"""
freezed_account = webnotes.conn.get_value("Account", account, "freeze_account")
if freezed_account == 'Yes' and not adv_adj \
and 'Accounts Manager' not in webnotes.user.get_roles():
webnotes.throw(_("Account") + ": " + account + _(" has been freezed. \
Only Accounts Manager can do transaction against this account"))

View File

@ -49,7 +49,7 @@ class DocType(AccountsController):
from accounts.utils import remove_against_link_from_jv
remove_against_link_from_jv(self.doc.doctype, self.doc.name, "against_jv")
self.make_gl_entries(cancel=1)
self.make_gl_entries()
def on_trash(self):
pass
@ -254,10 +254,10 @@ class DocType(AccountsController):
"against_voucher": d.against_voucher or d.against_invoice or d.against_jv,
"remarks": self.doc.remark,
"cost_center": d.cost_center
}, cancel)
})
)
if gl_map:
make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
make_gl_entries(gl_map, cancel=self.doc.docstatus==2, adv_adj=adv_adj)
def get_outstanding(self, args):
args = eval(args)

View File

@ -20,8 +20,7 @@ class DocType:
def get_voucher_details(self):
total_amount = webnotes.conn.sql("""select %s from `tabGL Entry`
where voucher_type = %s and voucher_no = %s
and account = %s and ifnull(is_cancelled, 'No') = 'No'""" %
where voucher_type = %s and voucher_no = %s and account = %s""" %
(self.doc.account_type, '%s', '%s', '%s'),
(self.doc.voucher_type, self.doc.voucher_no, self.doc.account))
@ -29,7 +28,7 @@ class DocType:
reconciled_payment = webnotes.conn.sql("""
select sum(ifnull(%s, 0)) - sum(ifnull(%s, 0)) from `tabGL Entry` where
against_voucher = %s and voucher_no != %s
and account = %s and ifnull(is_cancelled, 'No') = 'No'""" %
and account = %s""" %
((self.doc.account_type == 'debit' and 'credit' or 'debit'), self.doc.account_type,
'%s', '%s', '%s'), (self.doc.voucher_no, self.doc.voucher_no, self.doc.account))
@ -135,7 +134,6 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
where gle.account = '%(acc)s'
and gle.voucher_type = '%(dt)s'
and gle.voucher_no like '%(txt)s'
and ifnull(gle.is_cancelled, 'No') = 'No'
and (ifnull(gle.against_voucher, '') = ''
or ifnull(gle.against_voucher, '') = gle.voucher_no )
and ifnull(gle.%(account_type)s, 0) > 0
@ -143,8 +141,7 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
from `tabGL Entry`
where against_voucher_type = '%(dt)s'
and against_voucher = gle.voucher_no
and voucher_no != gle.voucher_no
and ifnull(is_cancelled, 'No') = 'No')
and voucher_no != gle.voucher_no)
!= abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)
)
%(mcond)s

View File

@ -325,12 +325,10 @@ class TestSalesInvoice(unittest.TestCase):
# cancel
si.cancel()
gle_count = webnotes.conn.sql("""select count(name) from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no=%s
and ifnull(is_cancelled, 'No') = 'Yes'
order by account asc""", si.doc.name)
gle = webnotes.conn.sql("""select * from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)
self.assertEquals(gle_count[0][0], 8)
self.assertFalse(gle)
def atest_pos_gl_entry_with_aii(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
@ -387,12 +385,10 @@ class TestSalesInvoice(unittest.TestCase):
# cancel
si.cancel()
gl_count = webnotes.conn.sql("""select count(name)
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
and ifnull(is_cancelled, 'No') = 'Yes'
order by account asc, name asc""", si.doc.name)
gle = webnotes.conn.sql("""select * from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no=%s""", si.doc.name)
self.assertEquals(gl_count[0][0], 16)
self.assertFalse(gle)
self.assertFalse(get_stock_and_account_difference([si.doclist[1].warehouse]))

View File

@ -8,14 +8,14 @@ from webnotes.model.doc import Document
def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True,
update_outstanding='Yes'):
if merge_entries:
gl_map = merge_similar_entries(gl_map)
if cancel:
set_as_cancel(gl_map[0]["voucher_type"], gl_map[0]["voucher_no"])
if not cancel:
if merge_entries:
gl_map = merge_similar_entries(gl_map)
check_budget(gl_map, cancel)
save_entries(gl_map, cancel, adv_adj, update_outstanding)
check_budget(gl_map, cancel)
save_entries(gl_map, adv_adj, update_outstanding)
else:
delete_gl_entries(gl_map, adv_adj, update_outstanding)
def merge_similar_entries(gl_map):
merged_gl_map = []
@ -52,7 +52,7 @@ def check_budget(gl_map, cancel):
if acc_details[0]=="Yes" and acc_details[1]=="Debit":
webnotes.get_obj('Budget Control').check_budget(gle, cancel)
def save_entries(gl_map, cancel, adv_adj, update_outstanding):
def save_entries(gl_map, adv_adj, update_outstanding):
total_debit = total_credit = 0.0
def _swap(gle):
gle.debit, gle.credit = abs(flt(gle.credit)), abs(flt(gle.debit))
@ -68,36 +68,38 @@ def save_entries(gl_map, cancel, adv_adj, update_outstanding):
if flt(gle.debit) < 0 or flt(gle.credit) < 0:
_swap(gle)
# toggled debit/credit in two separate condition because
# both should be executed at the
# time of cancellation when there is negative amount (tax discount)
if cancel:
_swap(gle)
gle_obj = webnotes.get_obj(doc=gle)
# validate except on_cancel
if not cancel:
gle_obj.validate()
# save
gle_obj.validate()
gle.save(1)
gle_obj.on_update(adv_adj, cancel, update_outstanding)
gle_obj.on_update(adv_adj, update_outstanding)
# update total debit / credit
total_debit += flt(gle.debit)
total_credit += flt(gle.credit)
if not cancel:
validate_total_debit_credit(total_debit, total_credit)
validate_total_debit_credit(total_debit, total_credit)
def validate_total_debit_credit(total_debit, total_credit):
if abs(total_debit - total_credit) > 0.005:
webnotes.msgprint("""Debit and Credit not equal for
this voucher: Diff (Debit) is %s""" %
(total_debit - total_credit), raise_exception=1)
def set_as_cancel(voucher_type, voucher_no):
webnotes.conn.sql("""update `tabGL Entry` set is_cancelled='Yes',
modified=%s, modified_by=%s
where voucher_type=%s and voucher_no=%s""",
(now(), webnotes.session.user, voucher_type, voucher_no))
webnotes.throw(_("Debit and Credit not equal for this voucher: Diff (Debit) is ") +
cstr(total_debit - total_credit))
def delete_gl_entries(gl_entries, adv_adj, update_outstanding):
from accounts.doctype.gl_entry.gl_entry import check_negative_balance, \
check_freezing_date, update_outstanding_amt, validate_freezed_account
check_freezing_date(gl_entries[0]["posting_date"], adv_adj)
webnotes.conn.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""",
(gl_entries[0]["voucher_type"], gl_entries[0]["voucher_no"]))
for entry in gl_entries:
validate_freezed_account(entry["account"], adv_adj)
check_negative_balance(entry["account"], adv_adj)
if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \
and update_outstanding == 'Yes':
update_outstanding_amt(entry["account"], entry.get("against_voucher_type"),
entry.get("against_voucher"))
# To-do
# Check and update budget for expense account

View File

@ -73,7 +73,7 @@ def get_gl_entries(filters, before_report_date=True):
conditions, supplier_accounts = get_conditions(filters, before_report_date)
gl_entries = []
gl_entries = webnotes.conn.sql("""select * from `tabGL Entry`
where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" %
where docstatus < 2 %s order by posting_date, account""" %
(conditions), tuple(supplier_accounts), as_dict=1)
return gl_entries
@ -126,7 +126,7 @@ def get_outstanding_amount(gle, report_date):
select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry`
where account = %s and posting_date <= %s and against_voucher_type = %s
and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",
and against_voucher = %s and name != %s""",
(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0]
outstanding_amount = flt(gle.credit) - flt(gle.debit) - flt(payment_amount)

View File

@ -65,7 +65,7 @@ def get_columns():
def get_gl_entries(filters, upto_report_date=True):
conditions, customer_accounts = get_conditions(filters, upto_report_date)
return webnotes.conn.sql("""select * from `tabGL Entry`
where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" %
where docstatus < 2 %s order by posting_date, account""" %
(conditions), tuple(customer_accounts), as_dict=1)
def get_conditions(filters, upto_report_date=True):
@ -116,7 +116,7 @@ def get_outstanding_amount(gle, report_date):
select sum(ifnull(credit, 0)) - sum(ifnull(debit, 0))
from `tabGL Entry`
where account = %s and posting_date <= %s and against_voucher_type = %s
and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",
and against_voucher = %s and name != %s""",
(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0]
return flt(gle.debit) - flt(gle.credit) - flt(payment_amount)
@ -130,7 +130,7 @@ def get_payment_amount(gle, report_date, entries_after_report_date):
payment_amount = webnotes.conn.sql("""
select sum(ifnull(credit, 0)) - sum(ifnull(debit, 0)) from `tabGL Entry`
where account = %s and posting_date <= %s and against_voucher_type = %s
and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",
and against_voucher = %s and name != %s""",
(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0]
return flt(payment_amount)

View File

@ -87,7 +87,7 @@ def get_actual_details(filters):
return webnotes.conn.sql("""select gl.account, gl.debit, gl.credit,
gl.cost_center, MONTHNAME(gl.posting_date) as month_name
from `tabGL Entry` gl, `tabBudget Detail` bd
where gl.fiscal_year=%s and company=%s and is_cancelled='No'
where gl.fiscal_year=%s and company=%s
and bd.account=gl.account""" % ('%s', '%s'),
(filters.get("fiscal_year"), filters.get("company")), as_dict=1)

View File

@ -48,7 +48,7 @@ def get_stock_ledger_entries(filters):
voucher_detail_no, posting_date, posting_time, stock_value,
warehouse, actual_qty as qty
from `tabStock Ledger Entry`
where ifnull(`is_cancelled`, "No") = "No" """
where ifnull(`is_cancelled`, 'No') = No'"""
if filters.get("company"):
query += """ and company=%(company)s"""

View File

@ -91,15 +91,10 @@ def get_balance_on(account=None, date=None):
else:
cond.append("""gle.account = "%s" """ % (account, ))
# join conditional conditions
cond = " and ".join(cond)
if cond:
cond += " and "
bal = webnotes.conn.sql("""
SELECT sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
FROM `tabGL Entry` gle
WHERE %s ifnull(is_cancelled, 'No') = 'No' """ % (cond, ))[0][0]
WHERE %s""" % " and ".join(cond))[0][0]
# if credit account, it should calculate credit - debit
if bal and acc.debit_or_credit == 'Credit':
@ -236,8 +231,7 @@ def remove_against_link_from_jv(ref_type, ref_no, against_field):
set against_voucher_type=null, against_voucher=null,
modified=%s, modified_by=%s
where against_voucher_type=%s and against_voucher=%s
and voucher_no != ifnull(against_voucher, "")
and ifnull(is_cancelled, "No")="No" """,
and voucher_no != ifnull(against_voucher, '')""",
(now(), webnotes.session.user, ref_type, ref_no))
@webnotes.whitelist()

View File

@ -330,11 +330,8 @@ class AccountsController(TransactionBase):
self.calculate_outstanding_amount()
def get_gl_dict(self, args, cancel=None):
def get_gl_dict(self, args):
"""this method populates the common properties of a gl entry record"""
if cancel is None:
cancel = (self.doc.docstatus == 2)
gl_dict = {
'company': self.doc.company,
'posting_date': self.doc.posting_date,
@ -342,7 +339,6 @@ class AccountsController(TransactionBase):
'voucher_no': self.doc.name,
'aging_date': self.doc.fields.get("aging_date") or self.doc.posting_date,
'remarks': self.doc.remarks,
'is_cancelled': cancel and "Yes" or "No",
'fiscal_year': self.doc.fiscal_year,
'debit': 0,
'credit': 0,

View File

@ -23,7 +23,7 @@ class StockController(AccountsController):
"against": against_stock_account,
"debit": amount,
"remarks": self.doc.remarks or "Accounting Entry for Stock",
}, self.doc.docstatus == 2),
}),
# account against stock in hand
self.get_gl_dict({
@ -32,7 +32,7 @@ class StockController(AccountsController):
"credit": amount,
"cost_center": cost_center or None,
"remarks": self.doc.remarks or "Accounting Entry for Stock",
}, self.doc.docstatus == 2),
}),
]
return gl_entries

View File

@ -311,7 +311,8 @@ class DocType(TransactionBase):
acc_head = webnotes.conn.sql("select name from `tabAccount` where company = '%s' and master_name = '%s'"%(obj.doc.company, obj.doc.customer))
if acc_head:
tot_outstanding = 0
dbcr = webnotes.conn.sql("select sum(debit), sum(credit) from `tabGL Entry` where account = '%s' and ifnull(is_cancelled, 'No')='No'" % acc_head[0][0])
dbcr = webnotes.conn.sql("""select sum(debit), sum(credit) from `tabGL Entry`
where account = %s""", acc_head[0][0])
if dbcr:
tot_outstanding = flt(dbcr[0][0])-flt(dbcr[0][1])

View File

@ -287,7 +287,7 @@ class DocType:
"""
Trash accounts and cost centers for this company if no gl entry exists
"""
rec = webnotes.conn.sql("SELECT name from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No' and company = %s", self.doc.name)
rec = webnotes.conn.sql("SELECT name from `tabGL Entry` where company = %s", self.doc.name)
if not rec:
# delete gl entry
webnotes.conn.sql("delete from `tabGL Entry` where company = %s", self.doc.name)

View File

@ -362,8 +362,8 @@ class DocType(DocListController):
gl_entries = webnotes.conn.sql("""select `account`,
ifnull(credit, 0) as credit, ifnull(debit, 0) as debit, `against`
from `tabGL Entry`
where company=%s and ifnull(is_cancelled, "No")="No" and
posting_date <= %s %s""" % ("%s", "%s",
where company=%s
and posting_date <= %s %s""" % ("%s", "%s",
from_date and "and posting_date>='%s'" % from_date or ""),
(self.doc.company, to_date or self.to_date), as_dict=1)

View File

@ -36,7 +36,6 @@ data_map = {
"GL Entry": {
"columns": ["name", "account", "posting_date", "cost_center", "debit", "credit",
"is_opening", "company", "voucher_type", "voucher_no", "remarks"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date, account",
"links": {
"account": ["Account", "name"],