ChatGPT and ERPNext

Have you tried the BOT, you may surprise yourself as I did :-

ME : Give me an example of JSON to POST a sales invoice with VAT component using Frappe REST API

ChatGPT: Here’s an example of a JSON payload to POST a sales invoice with a VAT component using the Frappe REST API:

Copy code
“doctype”: “Sales Invoice”,
“customer”: “Customer 1”,
“posting_date”: “2023-02-07”,
“items”: [
“item_code”: “Item 1”,
“qty”: 2,
“rate”: 100
“item_code”: “Item 2”,
“qty”: 1,
“rate”: 50
“taxes”: [
“charge_type”: “On Net Total”,
“account_head”: “VAT - Sales”,
“rate”: 20,
“tax_amount”: 40
“company”: “Company Name”
In this example, the JSON payload includes the required doctype field set to “Sales Invoice” and the customer field set to the name of the customer. The posting_date field is set to the date on which the invoice is posted.

The items field is an array of objects that describe each item included in the invoice. Each object in the items array includes the item_code, qty, and rate fields.

The taxes field is an array of objects that describe the tax components of the invoice. In this example, there is a single VAT component with a charge_type of “On Net Total”, an account_head of “VAT - Sales”, a rate of 20%, and a tax_amount of 40.

Finally, the company field is set to the name of the company for which the invoice is being submitted.

This is just one example of a JSON payload for submitting a sales invoice with a VAT component using the Frappe REST API. Depending on your specific requirements and setup, the JSON payload may need to be customized further.

ME: I want to create a security command center in ERPNext with a map to show emergency locations , generate for me the doc type

ChatGPT: To create a security command center in ERPNext with a map to show emergency locations, you would need to create a custom DocType. Here’s an example of the fields that you could include in the custom DocType:

doctype: Security Command Center


  • location_name:
    label: Location Name
    type: Data
    reqd: 1
  • emergency_type:
    label: Emergency Type
    type: Select
    options: [“Fire”, “Medical”, “Security”]
    reqd: 1
  • latitude:
    label: Latitude
    type: Float
    reqd: 1
  • longitude:
    label: Longitude
    type: Float
    reqd: 1
  • status:
    label: Status
    type: Select
    options: [“Active”, “Resolved”]
    reqd: 1
  • reported_on:
    label: Reported On
    type: Datetime
    reqd: 1
    In this example, the custom DocType is called “Security Command Center” and includes fields for the location name, emergency type, latitude, longitude, status, and date and time that the emergency was reported. The reqd field is set to 1 to indicate that the field is required.

You could then use this custom DocType to create records for each emergency location that is reported, and display the locations on a map using the latitude and longitude fields. The status field could be used to indicate whether the emergency is active or has been resolved.

This is just one example of how you could create a custom DocType for a security command center in ERPNext. Depending on your specific requirements, you may need to customize the fields further to meet your needs.

1 Like

I’ve tried it a few times but the scripts produced don’t seem to work.

I have found it useful to explain how specific scripts work though :slight_smile:


I’ve solved some of my Jinja problems with the help of ChatGTP. It knows ERPNext, Frappe Framework, Jinja. It also knows the ERP Market and the ERPNext status.



Here is the output that I am getting from ChatGPT.


Give code to get all the batches of an Item with available quantity count in a given warehouse in a custom app in erpnext.

Output (Py code):
As an AI language model, I am not able to access or interact with an ERP system. However, I can provide a general code structure that could be used as a reference for getting all batches of an item with available quantity count in a given warehouse in a custom app in ERPNext. The actual code implementation may vary based on the specific ERPNext system and requirements.

Here’s the general code structure:

from frappe import _

def get_available_batches(item_code, warehouse):
    # Get all batches of the item in the warehouse
    batches = frappe.get_all('Stock Ledger Entry', filters={
        'item_code': item_code,
        'warehouse': warehouse
    }, fields=['batch_no', 'SUM(actual_qty) as total_qty'], group_by='batch_no')
    available_batches = []
    # Check available quantity of each batch
    for batch in batches:
        if batch.total_qty > 0:
                'batch_no': batch.batch_no,
                'available_qty': batch.total_qty
    return available_batches


  • The get_available_batches function takes two parameters - item_code and warehouse.
  • It uses the frappe.get_all function to get all the stock ledger entries of the item in the warehouse.
  • The filters parameter is used to filter the entries by item code and warehouse.
  • The fields parameter is used to specify which fields to retrieve from the stock ledger entries - batch number and total quantity.
  • The group_by parameter is used to group the entries by batch number.
  • The function then iterates through the batches to check the available quantity of each batch.
  • If the total quantity of a batch is greater than zero, it is considered an available batch and its details are added to the available_batches list.
  • Finally, the function returns the list of available batches.

Note: The above code is just a general reference and may require further modifications to suit specific requirements and to ensure compatibility with the ERPNext system.

I have not tested this code. I have just copy pasted ChatGPT generated output.

1 Like


The translation function is so common that ChatGPT seems to think that we always need it, even if there’s nothing to translate. :rofl: