mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-14 12:25:09 +00:00
fix(bank_account): validation for is_company_account
(cherry picked from commit 7532ab01d6)
This commit is contained in:
@@ -42,8 +42,4 @@ frappe.ui.form.on("Bank Account", {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
is_company_account: function (frm) {
|
|
||||||
frm.set_df_property("account", "reqd", frm.doc.is_company_account);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Company Account",
|
"label": "Company Account",
|
||||||
|
"mandatory_depends_on": "is_company_account",
|
||||||
"options": "Account"
|
"options": "Account"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -98,6 +99,7 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Company",
|
"label": "Company",
|
||||||
|
"mandatory_depends_on": "is_company_account",
|
||||||
"options": "Company"
|
"options": "Company"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -252,7 +254,7 @@
|
|||||||
"link_fieldname": "default_bank_account"
|
"link_fieldname": "default_bank_account"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2025-08-29 12:32:01.081687",
|
"modified": "2026-01-20 00:46:16.633364",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Bank Account",
|
"name": "Bank Account",
|
||||||
|
|||||||
@@ -51,25 +51,29 @@ class BankAccount(Document):
|
|||||||
delete_contact_and_address("Bank Account", self.name)
|
delete_contact_and_address("Bank Account", self.name)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_company()
|
self.validate_is_company_account()
|
||||||
self.validate_account()
|
|
||||||
self.update_default_bank_account()
|
self.update_default_bank_account()
|
||||||
|
|
||||||
def validate_account(self):
|
def validate_is_company_account(self):
|
||||||
if self.account:
|
if self.is_company_account:
|
||||||
if accounts := frappe.db.get_all(
|
if not self.company:
|
||||||
"Bank Account", filters={"account": self.account, "name": ["!=", self.name]}, as_list=1
|
frappe.throw(_("Company is mandatory for company account"))
|
||||||
):
|
|
||||||
frappe.throw(
|
|
||||||
_("'{0}' account is already used by {1}. Use another account.").format(
|
|
||||||
frappe.bold(self.account),
|
|
||||||
frappe.bold(comma_and([get_link_to_form(self.doctype, x[0]) for x in accounts])),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_company(self):
|
if not self.account:
|
||||||
if self.is_company_account and not self.company:
|
frappe.throw(_("Company Account is mandatory"))
|
||||||
frappe.throw(_("Company is mandatory for company account"))
|
|
||||||
|
self.validate_account()
|
||||||
|
|
||||||
|
def validate_account(self):
|
||||||
|
if accounts := frappe.db.get_all(
|
||||||
|
"Bank Account", filters={"account": self.account, "name": ["!=", self.name]}, as_list=1
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_("'{0}' account is already used by {1}. Use another account.").format(
|
||||||
|
frappe.bold(self.account),
|
||||||
|
frappe.bold(comma_and([get_link_to_form(self.doctype, x[0]) for x in accounts])),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def update_default_bank_account(self):
|
def update_default_bank_account(self):
|
||||||
if self.is_default and not self.disabled:
|
if self.is_default and not self.disabled:
|
||||||
|
|||||||
Reference in New Issue
Block a user