/Automatically create a customer from a user?

Hi,

Is there an existing method that creates a Customer (in the ERpNext Selling Module) from a User (in the Core module)? What is the purpose of a User having a “Customer” role if a Customer document is not created?

Regards

Portal Settings allows you to assign a default role to a user on signup:

What’s the user to customer flow you’re looking at? Elaborating further can help other members to come up with a solution.

I understand this to give a User the “Customer” role upon signup, however this does not automatically create a corresponding record in the “Customer” doctype which is defined in the Selling module.

The user to customer flow is as follows:

  1. User has to signup before accessing a webform with a payment gateway. (The data being passed on to the payment gateway controller requires a logged in session user to send a valid “payer_email” data).
  2. Once the user has signed up, the user completes the webform and makes a payment.
  3. The payment gateway process should then create a sales invoice against the user (but a customer document for that user does not exist).
  4. Once a sales invoice is created, the payment gateway process should create a payment entry against the sales invoice.
  5. The user/customer should be able to view their sales invoice and the payment status. The “Customer” role is needed here but this can be catered for in step 1, where the default role can be changed to “Customer” or in step 3.

As you can see, step 3 is where my question stems from. Because I am developing my own Payment Gateway app, I can try cater for creating a Customer using the User details in the code, but I just want to know if there is an existing method (I have tried searching but could not find).

There are many cases like creating a new user for the existing customer. So admin should create and match records.

But creating a Company when a new user is created should be trivial with a Server Side Script.

Okay, so I see that a Contact is created when a User signs up. I can then use this information to create a Customer (if Customer does not yet exist) using Server side scripting.

If anyone comes across this, these are the steps I took:

  1. After a User is created, a corresponding Contact document is created where User.name==Contact.user
  2. Check if Customer exists on Customer.email_id==Contact.user
  3. If Customer does not exist then create Customer with Customer.customer_primary_contact== Contact.name to make sure there is a link with the User through Contact.

I think this process ensures there is no duplicate Customer records for a User.

2 Likes