Minor fixes related to account renaming and deletion

This commit is contained in:
Nabin Hait 2017-11-16 17:48:59 +05:30
parent a5ebebd09c
commit 1749b7c16b
3 changed files with 9 additions and 23 deletions

View File

@ -5,12 +5,12 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cint, cstr from frappe.utils import cint, cstr
from frappe import throw, _ from frappe import throw, _
from frappe.model.document import Document from frappe.utils.nestedset import NestedSet
class RootNotEditable(frappe.ValidationError): pass class RootNotEditable(frappe.ValidationError): pass
class BalanceMismatchError(frappe.ValidationError): pass class BalanceMismatchError(frappe.ValidationError): pass
class Account(Document): class Account(NestedSet):
nsm_parent_field = 'parent_account' nsm_parent_field = 'parent_account'
def onload(self): def onload(self):
@ -160,26 +160,12 @@ class Account(Document):
if not self.report_type: if not self.report_type:
throw(_("Report Type is mandatory")) throw(_("Report Type is mandatory"))
def on_trash(self):
def update_nsm_model(self): # checks gl entries and if child exists
"""update lft, rgt indices for nested set model"""
import frappe
import frappe.utils.nestedset
frappe.utils.nestedset.update_nsm(self)
def on_update(self):
self.update_nsm_model()
def validate_trash(self):
"""checks gl entries and if child exists"""
if self.check_gle_exists(): if self.check_gle_exists():
throw(_("Account with existing transaction can not be deleted")) throw(_("Account with existing transaction can not be deleted"))
if self.check_if_child_exists():
throw(_("Child account exists for this account. You can not delete this account."))
def on_trash(self): super(Account, self).on_trash()
self.validate_trash()
self.update_nsm_model()
def before_rename(self, old, new, merge=False): def before_rename(self, old, new, merge=False):
# Add company abbr if not provided # Add company abbr if not provided

View File

@ -6,7 +6,7 @@
"default_currency": "INR", "default_currency": "INR",
"doctype": "Company", "doctype": "Company",
"domain": "Manufacturing", "domain": "Manufacturing",
"chart_of_accounts": "India - Chart of Accounts", "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List" "default_holiday_list": "_Test Holiday List"
}, },
{ {
@ -16,7 +16,7 @@
"default_currency": "USD", "default_currency": "USD",
"doctype": "Company", "doctype": "Company",
"domain": "Retail", "domain": "Retail",
"chart_of_accounts": "India - Chart of Accounts", "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List" "default_holiday_list": "_Test Holiday List"
}, },
{ {
@ -26,7 +26,7 @@
"country": "Germany", "country": "Germany",
"doctype": "Company", "doctype": "Company",
"domain": "Retail", "domain": "Retail",
"chart_of_accounts": "India - Chart of Accounts", "chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List" "default_holiday_list": "_Test Holiday List"
} }
] ]

View File

@ -40,7 +40,7 @@ def before_tests():
"company_tagline" :"Testing", "company_tagline" :"Testing",
"email" :"test@erpnext.com", "email" :"test@erpnext.com",
"password" :"test", "password" :"test",
"chart_of_accounts" : "India - Chart of Accounts", "chart_of_accounts" : "Standard",
"domain" : "Manufacturing", "domain" : "Manufacturing",
}) })