diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index a9bbcb18d0..335d47caa1 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -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: diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index bdc64877cf..0dd36350cd 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -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)