fix: Gracefully handle duplicate bank account name to make setup faster
This commit is contained in:
parent
8ed1afd93d
commit
1001f29784
@ -28,6 +28,12 @@ class Account(NestedSet):
|
||||
from erpnext.accounts.utils import get_autoname_with_number
|
||||
self.name = get_autoname_with_number(self.account_number, self.account_name, None, self.company)
|
||||
|
||||
def before_insert(self):
|
||||
# Update Bank account name if conflicting with any other account
|
||||
if frappe.flags.in_install and self.account_type == 'Bank':
|
||||
if frappe.db.get_value('Account', {'account_name': self.account_name}):
|
||||
self.account_name = self.account_name + '-1'
|
||||
|
||||
def validate(self):
|
||||
from erpnext.accounts.utils import validate_field_number
|
||||
if frappe.local.flags.allow_unverified_charts:
|
||||
|
@ -188,24 +188,6 @@ def build_account_tree(tree, parent, all_accounts):
|
||||
# call recursively to build a subtree for current account
|
||||
build_account_tree(tree[child.account_name], child, all_accounts)
|
||||
|
||||
@frappe.whitelist()
|
||||
def validate_bank_account(coa, bank_account):
|
||||
accounts = []
|
||||
chart = get_chart(coa)
|
||||
|
||||
if chart:
|
||||
def _get_account_names(account_master):
|
||||
for account_name, child in iteritems(account_master):
|
||||
if account_name not in ["account_number", "account_type",
|
||||
"root_type", "is_group", "tax_rate"]:
|
||||
accounts.append(account_name)
|
||||
|
||||
_get_account_names(child)
|
||||
|
||||
_get_account_names(chart)
|
||||
|
||||
return (bank_account in accounts)
|
||||
|
||||
@frappe.whitelist()
|
||||
def build_tree_from_json(chart_template, chart_data=None):
|
||||
''' get chart template from its folder and parse the json to be rendered as tree '''
|
||||
|
@ -139,36 +139,10 @@ erpnext.setup.slides_settings = [
|
||||
},
|
||||
|
||||
validate: function () {
|
||||
let me = this;
|
||||
let exist;
|
||||
|
||||
if (!this.validate_fy_dates()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate bank name
|
||||
if(me.values.bank_account){
|
||||
frappe.call({
|
||||
async: false,
|
||||
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.validate_bank_account",
|
||||
args: {
|
||||
"coa": me.values.chart_of_accounts,
|
||||
"bank_account": me.values.bank_account
|
||||
},
|
||||
callback: function (r) {
|
||||
if(r.message){
|
||||
exist = r.message;
|
||||
me.get_field("bank_account").set_value("");
|
||||
let message = __('Account {0} already exists. Please enter a different name for your bank account.',
|
||||
[me.values.bank_account]
|
||||
);
|
||||
frappe.msgprint(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
return !exist; // Return False if exist = true
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user