From fbd706f232b6fa7fdf3cb7e560f07e9736228ce3 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 5 Jan 2022 17:55:08 +0530 Subject: [PATCH] fix: existing party link validation (#29159) --- erpnext/accounts/doctype/party_link/party_link.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/party_link/party_link.py b/erpnext/accounts/doctype/party_link/party_link.py index e9f813c17c..031a9fa4db 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 @@ -12,6 +12,17 @@ class PartyLink(Document): frappe.throw(_("Allowed primary roles are 'Customer' and 'Supplier'. Please select one of these roles only."), 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")