Skip to content

Commit 9838881

Browse files
Merge pull request #2 from redsoftware-hq/feature/lead-webhook
Feature/lead webhook
2 parents 671b01a + 22f5747 commit 9838881

File tree

20 files changed

+1019
-736
lines changed

20 files changed

+1019
-736
lines changed

onelead/meta_lead/doctype/meta_ads/meta_ads.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
],
6161
"index_web_pages_for_search": 1,
6262
"links": [],
63-
"modified": "2024-11-19 22:52:01.322993",
63+
"modified": "2025-02-18 13:33:48.990232",
6464
"modified_by": "Administrator",
6565
"module": "Meta Lead",
6666
"name": "Meta Ads",
@@ -80,6 +80,7 @@
8080
"write": 1
8181
}
8282
],
83+
"search_fields": "ads_name, campaign",
8384
"show_title_field_in_link": 1,
8485
"sort_field": "modified",
8586
"sort_order": "DESC",

onelead/meta_lead/doctype/meta_ads_page_config/meta_ads_page_config.js

Lines changed: 296 additions & 243 deletions
Large diffs are not rendered by default.

onelead/meta_lead/doctype/meta_campaign_form_list/meta_campaign_form_list.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"fetch_from": "meta_lead_form.form_name",
2828
"fieldname": "form_name",
2929
"fieldtype": "Read Only",
30+
"in_list_view": 1,
3031
"in_preview": 1,
3132
"label": "Form Name"
3233
},
@@ -52,8 +53,6 @@
5253
"fieldname": "campaign",
5354
"fieldtype": "Link",
5455
"in_filter": 1,
55-
"in_list_view": 1,
56-
"in_preview": 1,
5756
"in_standard_filter": 1,
5857
"label": "Campaign",
5958
"options": "Meta Campaign",
@@ -63,7 +62,7 @@
6362
"index_web_pages_for_search": 1,
6463
"istable": 1,
6564
"links": [],
66-
"modified": "2024-11-20 00:34:32.273912",
65+
"modified": "2025-03-06 00:50:29.294400",
6766
"modified_by": "Administrator",
6867
"module": "Meta Lead",
6968
"name": "Meta Campaign Form List",

onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,71 @@ frappe.ui.form.on("Meta Lead Form", {
6767
}
6868
}
6969
});
70-
});
70+
})
71+
.attr('title', __('Create a new Campaign document using fields from this form, If not, this will be created automatically when leads are received.'));
72+
73+
}
74+
75+
if (!frm.doc.ads) {
76+
// ----- NEW BUTTON: Create Ads -----
77+
frm.add_custom_button(__('Create Ads'), function () {
78+
// 1. Generate an Ads ID and Ads Name
79+
const adsId = (frm.doc.form_name || "Ad") + "_" + (frm.doc.form_id || "");
80+
const adsName = frm.doc.form_name || `Ads for ${frm.doc.form_id}`;
81+
82+
// 2. Validate necessary fields
83+
if (!frm.doc.campaign) {
84+
frappe.msgprint(__('Please link a Campaign first before creating Ads'));
85+
return;
86+
}
87+
88+
// 3. Check if a Meta Ads doc with the derived Ads ID already exists
89+
frappe.call({
90+
method: "frappe.client.get_list",
91+
args: {
92+
doctype: "Meta Ads",
93+
filters: { ads_id: adsId },
94+
fields: ["name", "ads_name"]
95+
},
96+
callback: function (r) {
97+
if (r.message && r.message.length > 0) {
98+
// Found an existing Ads doc
99+
const existingAds = r.message[0];
100+
frappe.msgprint(__("Ads already exists: ") + existingAds.ads_name);
101+
102+
// Link that Ads doc to this form (assuming you have a 'meta_ads' link field or similar)
103+
frm.set_value("meta_ads", existingAds.name);
104+
frm.save();
105+
} else {
106+
// 4. Insert a new Meta Ads record
107+
frappe.call({
108+
method: "frappe.client.insert",
109+
args: {
110+
doc: {
111+
doctype: "Meta Ads",
112+
ads_id: adsId,
113+
ads_name: adsName,
114+
status: frm.doc.status,
115+
campaign: frm.doc.campaign,
116+
has_lead_form: 1 // or whatever your checkbox field is named
117+
}
118+
},
119+
callback: function (res) {
120+
if (!res.exc) {
121+
const adsDoc = res.message;
122+
frappe.msgprint(__("New Ads created: ") + adsDoc.ads_name);
123+
124+
// Link the newly created Ads to this form
125+
frm.set_value("meta_ads", adsDoc.name);
126+
frm.save();
127+
}
128+
}
129+
});
130+
}
131+
}
132+
});
133+
})
134+
.attr('title', __('Create a new Meta Ads document using fields from this form, If not, this will be created automatically when leads are received.'));
71135
}
72136
}
73137
});

onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
{
5252
"fieldname": "ads",
5353
"fieldtype": "Link",
54+
"hidden": 1,
5455
"label": "Ads",
5556
"options": "Meta Ads"
5657
},
@@ -157,7 +158,7 @@
157158
],
158159
"index_web_pages_for_search": 1,
159160
"links": [],
160-
"modified": "2024-12-28 18:42:11.538615",
161+
"modified": "2025-02-12 23:34:35.747040",
161162
"modified_by": "Administrator",
162163
"module": "Meta Lead",
163164
"name": "Meta Lead Form",

onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def on_update(self):
2626
After insert, if `assign_to` or `assignee_doctype` are changed and a campaign is linked,
2727
update the linked campaign with the new values.
2828
"""
29+
# TODO: 1a - 1c: Remove the logic in light of the new M:M relationship between `Meta Lead Form` and `Meta Campaign`
2930
if self.campaign:
3031
# Fetch the linked campaign
3132
campaign = frappe.get_doc("Meta Campaign", self.campaign)

onelead/meta_lead/doctype/meta_lead_form_mapping/meta_lead_form_mapping.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"meta_field",
1010
"lead_doctype_field",
1111
"default_value",
12-
"formatting_function"
12+
"formatting_function",
13+
"function_parameters"
1314
],
1415
"fields": [
1516
{
@@ -41,14 +42,19 @@
4142
"allow_in_quick_entry": 1,
4243
"description": "Add custom python function to process and format meta field value for Lead DOCTYPE entry.",
4344
"fieldname": "formatting_function",
44-
"fieldtype": "Code",
45+
"fieldtype": "Select",
4546
"label": "Formatting function"
47+
},
48+
{
49+
"fieldname": "function_parameters",
50+
"fieldtype": "Code",
51+
"label": "Function Parameters"
4652
}
4753
],
4854
"index_web_pages_for_search": 1,
4955
"istable": 1,
5056
"links": [],
51-
"modified": "2024-11-13 01:56:28.812630",
57+
"modified": "2025-03-06 01:21:19.404169",
5258
"modified_by": "Administrator",
5359
"module": "Meta Lead",
5460
"name": "Meta Lead Form Mapping",

onelead/meta_lead/doctype/meta_lead_logs/__init__.py

Whitespace-only changes.

onelead/meta_lead/doctype/meta_lead_logs/meta_lead_logs.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

onelead/meta_lead/doctype/meta_lead_logs/meta_lead_logs.json

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)