delete customer account on deletion of customer record

This commit is contained in:
Nabin Hait 2012-06-22 13:35:13 +05:30
parent 4ce8e16ded
commit 318eab813c
2 changed files with 18 additions and 2 deletions

View File

@ -169,6 +169,13 @@ class DocType:
get_obj('Account', self.doc.parent_account).update_balance(fy, period_det, flag)
msgprint('Balances updated')
def validate_mandatory(self):
if not self.doc.debit_or_credit:
msgprint("Debit or Credit field is mandatory", raise_exception=1)
if not self.doc.is_pl_account:
msgprint("Is PL Account field is mandatory", raise_exception=1)
# VALIDATE
# ==================================================================
def validate(self):
@ -177,6 +184,7 @@ class DocType:
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
# Defaults
if not self.doc.parent_account:

View File

@ -239,12 +239,20 @@ class DocType:
webnotes.conn.sql("""\
delete from `tabCommunication`
where customer = %s and supplier is null""", self.doc.name)
# ******************************************************* on trash *********************************************************
def delete_customer_account(self):
"""delete customer's ledger if exist and check balance before deletion"""
acc = sql("select name from `tabAccount` where master_type = 'Customer' \
and master_name = %s and docstatus < 2", self.doc.name)
if acc:
from webnotes.model import delete_doc
delete_doc('Account', acc[0][0])
def on_trash(self):
self.delete_customer_address()
self.delete_customer_contact()
self.delete_customer_communication()
self.delete_customer_account()
if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)