How to insert doctype data like items ,customer etc from python script?

hello all, small help will be appriciated !! actually i have a csv file which contains item,customer etc details.now i have to insert these data by using a python script. my doubt is can i run my python script from a installed custome app in erpnext.
my approch to python prgm is like converting the csv file into pandas dataframe and based on the columns i want to enter the particular data to particular doctype in database. and also please let me know do i have to install pandas if yes and how?

Hi,

Yes, you can run your Python script from an installed custom app in ERPNext. To do this, you can create a custom button or a custom page in your app and execute your script when the button is clicked or the page is accessed.

To insert data into ERPNext using Python, you can use the Frappe framework. You can use the frappe.get_doc function to create new documents and insert data into the database.

Here is an example of how you can insert data into the “Customer” doctype:

import frappe

# read the csv file into a pandas dataframe
df = pandas.read_csv('file.csv')

# loop through the rows of the dataframe and insert data into ERPNext
for index, row in df.iterrows():
    customer = frappe.get_doc({
        "doctype": "Customer",
        "customer_name": row["customer_name"],
        "email_id": row["email_id"],
        # add more fields here as required
    })
    customer.insert()

Then, for installing the pandas you can use this commend on your terminal:

pip install pandas

Hope this will help you out.

Thank you.

2 Likes

thank you for your response this is helping me ,and i have a small doubt.Can custom button be created from a custom app and execute the python script or shall i create a custom button from customer.js