How to create a simple new customer form?

I’ve been trying for hours to find a way to have a simple “New Customer” form where all the basic information will be present on a single page , without tabs or anything else. The idea is to load this page and hand out the tablet to the new customer so that they can enter all their details on a single page. I tried either customizing the Customer (Selling) form or creating a web form ,but none of those options allow me to have the necessary “Address Line 1 , Country, Province” and etc fields that are required for the address and it only allows my to add the Customer Primary Address field , where a drop down menu appears and + new address becomes available. I want to avoid having to click multiple places in order to have all the needed details of our new customers. I couldn’t not find a way to customize the small New Customer form ,but only the full form.

I’m wondering whats the best course of action to create that simple page. We are looking into implementing a complete ERP for our small business where our drivers/salesmen can keep things super simple and just hand out a tablet to the new customers , have their details and then proceed to sell their products right away. ERPnext sure sounds like it can do all that , but the learning curve is a bit steep, although our needs are pretty basic so once I get through this it should be a breeze to operate…

Any help / guidance on how I should proceed to achieve this simple goal is welcomed! Thanks in advance.

Check out the Web Form doctype maybe. It might do what you need.

https://docs.frappe.io/framework/user/en/web-form

1 Like

Thanks for your response. As I delve deeper into ERPnext I’m beginning to understand the limitations I’m facing. What I understand is I cannot combine 2 doctypes in the same form , and that’s probably why the address fields are not available when I’m customizing the customer form. Same happens when I’m making a web form (which I had also looked into yesterday). My current idea now is to possible make 2 web forms that follow each other ? The first would have the customer enter the details of his company , then he would click NEXT/SAVE and a new form would appear with his address details. I’m going to look into this right away, but if anyone has tips on how this could be achieved , I’m all ears.

Thanks for your input, really appreciated.

Using chatGPT I figured out it would be possible to create a new Doctype with all the fields I require and then use a script to parse the collected data and place it in it’s respective doctypes. I could then make a custom form that has all the fields I need. GPT suggests a server script but since I’m still using the 14 day trial I currently do not have access to enable server scripts. Either I will host my own server so I can do my tests or GPT offered a client script that could call the API to save the data. So currently that’s what I’m looking into.

Hi @Roamin:

Maybe you can do this:

  • Create a new doctype called “New customer application” or whatever, with all the data you want to collect.

  • Use a server script to create customer and contact data on Customer and Contact doctype …

Hope this helps.

1 Like

I was typing a reply suggesting something similar. The Customer doctype is a bit complicated because of the one-to-many relationship Customers have with Addresses.

You could create a new doctype called “Customer Registration” or the like, then use it to generate a Customer doctype using a server script with whatever custom logic you need. You could also just add some custom fields to the original Customer doctype (registration_address_city, etc.), and then use the doctype’s on_insert hook to create and link address documents. I think I like the new doctype idea a bit better, as it seems a bit more future proof.

You could also create an entirely custom form using the Web Page doctype, then feed the data into a API-type server script. That would give you the most flexibility, but it would require more work.

In any case, all hail king ChatGPT

Edit: @avc is, as usual, faster and clearer :slight_smile:

1 Like

:joy: :joy: :joy: Love this kind of mind webhooks xD

1 Like

Not sure I’d the doctype called Doctype Layout works?

I have play around with some simple fields and it seem okay.

Hi @kittiu:

As far I know, you can just use doctype fields …

(post deleted by author)

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!")

Huh, interesting. As usual, ChatGPT is impressively correct about some things and bafflingly wrong about others.

The client script is trying to duplicate what the server script does, which isn’t a good idea. You’re probably better off doing this all server-side anyway, so I think you can just scrap the client script entirely. If you’re using a Web Form interface, I believe server script is your only option.

The server script is a bit odd too. You don’t need to import frappe, and I think it will throw an error. The create_customer_and_address method gets defined but never called. Other than that, the get_doc calls and the insert calls seem to look at least mostly okay (assuming your new doctype has fields with those names).

Thanks for the clarification. I had downloaded the VM for the server and I’m currently running it. I will re-create my basic doctype and will test the server script there , keeping your notes as a reference to guide gpt. I will be testing a bit for the next hour or so and beyond that it will be next monday as my week is almost done.

Once again, thanks to everyone for tips , suggestions and ideas. This feedback shows I probably chose the right system for my needs, simply based on open source & the community.

:blue_heart:

1 Like

Quick update, I managed to do what I was after using a server script on an installed VM so i could enable server scripts and giving GPT the feedback from peterg on the server script. My new doctype , when saved , properly populates a customer and its address and it can be used in sales invoice and etc.

Once again I can’t thank you all enough. Have a great week-end!

1 Like

Great! ERPNext doesn’t always do quite as much right out of the box, but the upside to that is its flexibility. A little bit of custom scripting is often all you need to do anything you can imagine.