feat: Demo data creation
This commit is contained in:
parent
20de27d480
commit
8ef257abbc
@ -70,6 +70,8 @@ treeviews = [
|
||||
"Department",
|
||||
]
|
||||
|
||||
demo_doctypes = ["items"]
|
||||
|
||||
jinja = {
|
||||
"methods": [
|
||||
"erpnext.stock.serial_batch_bundle.get_serial_or_batch_nos",
|
||||
|
49
erpnext/setup/demo.py
Normal file
49
erpnext/setup/demo.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def setup_demo_data():
|
||||
create_demo_company()
|
||||
process_demo_data()
|
||||
make_transactions()
|
||||
|
||||
|
||||
def create_demo_company():
|
||||
company = frappe.db.get_value("Company", {"docstatus": 0})
|
||||
company_doc = frappe.get_doc("Company", company)
|
||||
|
||||
# Make a dummy company
|
||||
new_company = frappe.new_doc("Company")
|
||||
new_company.company_name = company_doc.company_name + " (Demo)"
|
||||
new_company.abbr = company_doc.abbr + "D"
|
||||
new_company.enable_perpetual_inventory = 1
|
||||
new_company.default_currency = company_doc.default_currency
|
||||
new_company.country = company_doc.country
|
||||
new_company.chart_of_accounts_based_on = "Standard Template"
|
||||
new_company.chart_of_accounts = company_doc.chart_of_accounts
|
||||
new_company.insert()
|
||||
|
||||
|
||||
def process_demo_data():
|
||||
demo_doctypes = frappe.get_hooks("demo_doctypes") or []
|
||||
path = os.path.join(os.path.dirname(__file__), "demo_data")
|
||||
for doctype in demo_doctypes:
|
||||
with open(os.path.join(path, doctype + ".json"), "r") as f:
|
||||
data = f.read()
|
||||
if data:
|
||||
for item in json.loads(data):
|
||||
create_demo_record(item)
|
||||
|
||||
|
||||
def create_demo_record(doctype):
|
||||
frappe.get_doc(doctype).insert(ignore_permissions=True)
|
||||
|
||||
|
||||
def make_transactions():
|
||||
pass
|
62
erpnext/setup/demo_data/items.json
Normal file
62
erpnext/setup/demo_data/items.json
Normal file
@ -0,0 +1,62 @@
|
||||
[
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU001",
|
||||
"item_name": "T-shirt",
|
||||
"image": "https://www.shutterstock.com/image-photo/close-man-blank-tshirt-140861086"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU002",
|
||||
"item_name": "Laptop",
|
||||
"image": "https://www.shutterstock.com/image-photo/laptop-computer-blank-screen-isolated-on-1721445466"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU003",
|
||||
"item_name": "Book",
|
||||
"image": "https://www.shutterstock.com/image-vector/blank-vertical-book-cover-template-pages-172777709"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU004",
|
||||
"item_name": "Smartphone",
|
||||
"image": "https://www.shutterstock.com/image-vector/realistic-smartphone-mockup-front-back-1450789832"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU005",
|
||||
"item_name": "Sneakers",
|
||||
"image": "https://www.shutterstock.com/image-photo/white-sneaker-sport-shoe-on-purple-2155395817"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU006",
|
||||
"item_name": "Coffee Mug",
|
||||
"image": "https://www.shutterstock.com/image-vector/realistic-white-cup-isolated-on-transparent-585104080"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU007",
|
||||
"item_name": "Television",
|
||||
"image": "https://www.shutterstock.com/image-photo/tv-flat-screen-lcd-plasma-realistic-314401364"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU008",
|
||||
"item_name": "Backpack",
|
||||
"image": "https://www.shutterstock.com/image-photo/school-backpack-on-white-background-1440715766"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU009",
|
||||
"item_name": "Headphones",
|
||||
"image": "https://www.shutterstock.com/image-illustration/3d-rendering-yellow-headphones-isolated-on-1833307018"
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "SKU010",
|
||||
"item_name": "Camera",
|
||||
"image": "https://www.shutterstock.com/image-photo/camera-610909205"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user