fix: existing party link validation (#29159)
diff --git a/erpnext/accounts/doctype/party_link/party_link.py b/erpnext/accounts/doctype/party_link/party_link.py
index e9f813c..031a9fa 100644
--- a/erpnext/accounts/doctype/party_link/party_link.py
+++ b/erpnext/accounts/doctype/party_link/party_link.py
@@ -2,7 +2,7 @@
# For license information, please see license.txt
import frappe
-from frappe import _
+from frappe import _, bold
from frappe.model.document import Document
@@ -13,6 +13,17 @@
title=_("Invalid Primary Role"))
existing_party_link = frappe.get_all('Party Link', {
+ 'primary_party': self.primary_party,
+ 'secondary_party': self.secondary_party
+ }, pluck="primary_role")
+ if existing_party_link:
+ frappe.throw(_('{} {} is already linked with {} {}')
+ .format(
+ self.primary_role, bold(self.primary_party),
+ self.secondary_role, bold(self.secondary_party)
+ ))
+
+ existing_party_link = frappe.get_all('Party Link', {
'primary_party': self.secondary_party
}, pluck="primary_role")
if existing_party_link: