delete all cancelled gl entry on account deletion

This commit is contained in:
Nabin Hait 2012-02-20 13:04:36 +05:30
parent e08b9425cb
commit 6ac0be5fb2

View File

@ -203,7 +203,6 @@ class DocType:
# Add curret year balance # Add curret year balance
self.set_year_balance() self.set_year_balance()
# Check user role for approval process # Check user role for approval process
# ================================================================== # ==================================================================
def get_authorized_user(self): def get_authorized_user(self):
@ -232,7 +231,7 @@ class DocType:
# ================================================================== # ==================================================================
def check_balance_before_trash(self): def check_balance_before_trash(self):
if self.check_gle_exists(): if self.check_gle_exists():
msgprint("Account with existing transaction can not be trashed", raise_exception=1) msgprint("Account with existing transaction (Sales Invoice / Purchase Invoice / Journal Voucher) can not be trashed", raise_exception=1)
if self.check_if_child_exists(): if self.check_if_child_exists():
msgprint("Child account exists for this account. You can not trash this account.", raise_exception=1) msgprint("Child account exists for this account. You can not trash this account.", raise_exception=1)
@ -248,10 +247,14 @@ class DocType:
def on_trash(self): def on_trash(self):
# Check balance before trash # Check balance before trash
self.check_balance_before_trash() self.check_balance_before_trash()
# rebuild tree # rebuild tree
set(self.doc,'old_parent', '') set(self.doc,'old_parent', '')
self.update_nsm_model() 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)
#delete Account Balance #delete Account Balance
sql("delete from `tabAccount Balance` where account = %s", self.doc.name) sql("delete from `tabAccount Balance` where account = %s", self.doc.name)
@ -260,6 +263,8 @@ class DocType:
def on_restore(self): def on_restore(self):
# rebuild tree # rebuild tree
self.update_nsm_model() self.update_nsm_model()
# intiate balances
self.set_year_balance()
# on rename # on rename
# --------- # ---------