diff --git a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json index 19c2907a..4f3a859a 100644 --- a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json +++ b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json @@ -62,8 +62,7 @@ "fieldname": "facebook_lead_form", "fieldtype": "Link", "label": "Facebook Lead Form", - "options": "Facebook Lead Form", - "unique": 1 + "options": "Facebook Lead Form" }, { "default": "1", @@ -75,7 +74,7 @@ "grid_page_length": 50, "index_web_pages_for_search": 1, "links": [], - "modified": "2025-10-02 12:33:45.810895", + "modified": "2025-10-03 21:13:25.660629", "modified_by": "Administrator", "module": "Lead Syncing", "name": "Lead Sync Source", diff --git a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py index 2e2cc81b..37f89a67 100644 --- a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py +++ b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py @@ -24,6 +24,21 @@ class LeadSyncSource(Document): type: DF.Literal["Facebook"] # end: auto-generated types + def validate(self): + self.validate_same_fb_form_active() + + def validate_same_fb_form_active(self): + if not self.enabled: + return + + if not self.facebook_lead_form: + return + + already_active = frappe.db.exists("Lead Sync Source", {"enabled": 1, "facebook_lead_form": self.facebook_lead_form}) + + if already_active: + frappe.throw(frappe._("A lead sync source is already enabled for this Facebook Lead Form!")) + def before_save(self): if self.type == "Facebook" and self.access_token: # fetch_and_store_pages_from_facebook(self.access_token)