ChatGPT: Using ChatGPT for frappe

Hey folks ,

Just tried ChatGPT for frappe :crazy_face:

how to create doctype in frappe

In Frappe Framework, a “doctype” is a way to define a new document type, similar to a table in a relational database. To create a new doctype in Frappe, you can use the bench command-line tool. Here’s an example of how to create a new doctype called “My Doctype”:

Copy code

bench new-doctype My Doctype

This command will create a new folder in your Frappe app’s /frappe-bench/apps/ directory, with the name of your doctype, and it will contain all the necessary files for your new doctype, including the __init__.py, controller.py, and doctype.json files.

Then you can define the fields of your doctype in doctype.json file. Here is an example of how to define a text field called “my_field” in the “My Doctype” doctype:

Copy code

{
  "fields": [
    {
      "fieldname": "my_field",
      "fieldtype": "Data",
      "label": "My Field"
    }
  ]
}

After that, you need to run bench --site <sitename> install-app <appname> command to install the app to your site.

And finally, you can use the frappe.get_doc() function to create a new document of your doctype and set the fields’ values, for example:

Copy code

new_doc = frappe.get_doc({
    "doctype": "My Doctype",
    "my_field": "My Value"
})
new_doc.insert()

Keep in mind, this is just a basic example, and you can customize the fields, properties, and methods of your doctype according to your requirements.


5 Likes

this command exists?

ChatGPT should visit docs section … :joy:
Is pretty crazy.