refactor: disallow two active sources for same form
This commit is contained in:
parent
cd366839fc
commit
788fe36cfa
@ -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",
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user