Thanks for everyone’s input! I also think a custom doctype and a script will be the way to go. GPT’s current client script didn’t seem to work. I’m going to start poking GPT until he comes up with a correct script, or I will host my server and try the server script it provided. For the curious gurus , here’s the scripts GPT provided :
frappe.ui.form.on('New Customer Entry', {
after_save: function(frm) {
// Step 1: Create Customer via API
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Customer",
customer_name: frm.doc.customer_name,
email_id: frm.doc.email_address,
phone: frm.doc.phone_number,
customer_group: "Commercial", // Adjust as needed
territory: "All Territories"
}
},
callback: function(response) {
if (response.message) {
let customer_name = response.message.name;
frappe.msgprint(`Customer ${customer_name} created successfully!`);
// Step 2: Create Billing Address Linked to Customer
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Address",
address_title: frm.doc.customer_name,
address_line1: frm.doc.billing_address_line1,
city: frm.doc.billing_address_city,
pincode: frm.doc.billing_address_postal_code,
address_type: "Billing",
links: [{"link_doctype": "Customer", "link_name": customer_name}]
}
},
callback: function() {
frappe.msgprint("Billing Address created successfully!");
}
});
// Step 3: Create Shipping Address if Provided
if (frm.doc.shipping_address_line1) {
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Address",
address_title: frm.doc.customer_name,
address_line1: frm.doc.shipping_address_line1,
city: frm.doc.shipping_address_city,
pincode: frm.doc.shipping_address_postal_code,
address_type: "Shipping",
links: [{"link_doctype": "Customer", "link_name": customer_name}]
}
},
callback: function() {
frappe.msgprint("Shipping Address created successfully!");
}
});
}
}
}
});
}
});
Here’s the server script it provided :
import frappe
def create_customer_and_address(doc, method):
# Step 1: Create Customer Entry
customer = frappe.get_doc({
"doctype": "Customer",
"customer_name": doc.customer_name,
"email_id": doc.email_address,
"phone": doc.phone_number,
"customer_group": "Commercial", # Adjust based on your setup
"territory": "All Territories"
})
customer.insert(ignore_permissions=True) # Save the customer
# Step 2: Create Billing Address Entry
billing_address = frappe.get_doc({
"doctype": "Address",
"address_title": doc.customer_name,
"address_line1": doc.billing_address_line1,
"city": doc.billing_address_city,
"pincode": doc.billing_address_postal_code,
"address_type": "Billing",
"links": [{"link_doctype": "Customer", "link_name": customer.name}]
})
billing_address.insert(ignore_permissions=True) # Save billing address
# Step 3: Create Shipping Address Entry (If Provided)
if doc.shipping_address_line1:
shipping_address = frappe.get_doc({
"doctype": "Address",
"address_title": doc.customer_name,
"address_line1": doc.shipping_address_line1,
"city": doc.shipping_address_city,
"pincode": doc.shipping_address_postal_code,
"address_type": "Shipping",
"links": [{"link_doctype": "Customer", "link_name": customer.name}]
})
shipping_address.insert(ignore_permissions=True) # Save shipping address
frappe.msgprint(f"Customer '{customer.customer_name}' and Addresses Created Successfully!")