mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
feat: Clear demo data
This commit is contained in:
@@ -669,7 +669,7 @@ def get_payment_terms_template(party_name, party_type, company=None):
|
|||||||
if party_type not in ("Customer", "Supplier"):
|
if party_type not in ("Customer", "Supplier"):
|
||||||
return
|
return
|
||||||
template = None
|
template = None
|
||||||
print(party_type, party_name)
|
|
||||||
if party_type == "Customer":
|
if party_type == "Customer":
|
||||||
customer = frappe.get_cached_value(
|
customer = frappe.get_cached_value(
|
||||||
"Customer", party_name, fieldname=["payment_terms", "customer_group"], as_dict=1
|
"Customer", party_name, fieldname=["payment_terms", "customer_group"], as_dict=1
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ def setup_demo_data():
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def clear_demo_data():
|
def clear_demo_data():
|
||||||
company = frappe.db.get_single_value("Global Defaults", "demo_company")
|
company = erpnext.get_default_company()
|
||||||
create_transaction_deletion_record(company)
|
create_transaction_deletion_record(company)
|
||||||
|
clear_masters()
|
||||||
|
delete_company(company)
|
||||||
|
|
||||||
|
|
||||||
def create_demo_company():
|
def create_demo_company():
|
||||||
company = frappe.db.get_value("Company", {"docstatus": 0})
|
company = erpnext.get_default_company()
|
||||||
company_doc = frappe.get_doc("Company", company)
|
company_doc = frappe.get_doc("Company", company)
|
||||||
|
|
||||||
# Make a dummy company
|
# Make a dummy company
|
||||||
@@ -37,19 +39,19 @@ def create_demo_company():
|
|||||||
new_company.chart_of_accounts = company_doc.chart_of_accounts
|
new_company.chart_of_accounts = company_doc.chart_of_accounts
|
||||||
new_company.insert()
|
new_company.insert()
|
||||||
|
|
||||||
frappe.db.set_single_value("Global Defaults", "demo_company", new_company.name)
|
frappe.db.set_single_value("Global Defaults", "original_default_company", company)
|
||||||
|
|
||||||
|
# Set Demo Company as default to
|
||||||
|
frappe.db.set_single_value("Global Defaults", "default_company", new_company.name)
|
||||||
return new_company.name
|
return new_company.name
|
||||||
|
|
||||||
|
|
||||||
def process_masters():
|
def process_masters():
|
||||||
demo_doctypes = frappe.get_hooks("demo_master_doctypes") or []
|
for doctype in frappe.get_hooks("demo_master_doctypes"):
|
||||||
path = os.path.join(os.path.dirname(__file__), "demo_data")
|
data = read_data_file_using_hooks(doctype)
|
||||||
for doctype in demo_doctypes:
|
if data:
|
||||||
with open(os.path.join(path, doctype + ".json"), "r") as f:
|
for item in json.loads(data):
|
||||||
data = f.read()
|
create_demo_record(item)
|
||||||
if data:
|
|
||||||
for item in json.loads(data):
|
|
||||||
create_demo_record(item)
|
|
||||||
|
|
||||||
|
|
||||||
def create_demo_record(doctype):
|
def create_demo_record(doctype):
|
||||||
@@ -57,14 +59,11 @@ def create_demo_record(doctype):
|
|||||||
|
|
||||||
|
|
||||||
def make_transactions(company):
|
def make_transactions(company):
|
||||||
transaction_doctypes = frappe.get_hooks("demo_transaction_doctypes") or []
|
for doctype in frappe.get_hooks("demo_transaction_doctypes"):
|
||||||
path = os.path.join(os.path.dirname(__file__), "demo_data")
|
data = read_data_file_using_hooks(doctype)
|
||||||
for transaction in transaction_doctypes:
|
if data:
|
||||||
with open(os.path.join(path, transaction + ".json"), "r") as f:
|
for item in json.loads(data):
|
||||||
data = f.read()
|
create_transaction(item, company)
|
||||||
if data:
|
|
||||||
for item in json.loads(data):
|
|
||||||
create_transaction(item, company)
|
|
||||||
|
|
||||||
|
|
||||||
def create_transaction(doctype, company):
|
def create_transaction(doctype, company):
|
||||||
@@ -93,3 +92,32 @@ def create_transaction_deletion_record(company):
|
|||||||
transaction_deletion_record.company = company
|
transaction_deletion_record.company = company
|
||||||
transaction_deletion_record.save(ignore_permissions=True)
|
transaction_deletion_record.save(ignore_permissions=True)
|
||||||
transaction_deletion_record.submit()
|
transaction_deletion_record.submit()
|
||||||
|
|
||||||
|
|
||||||
|
def clear_masters():
|
||||||
|
for doctype in frappe.get_hooks("demo_master_doctypes")[::-1]:
|
||||||
|
data = read_data_file_using_hooks(doctype)
|
||||||
|
if data:
|
||||||
|
for item in json.loads(data):
|
||||||
|
clear_demo_record(item)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_demo_record(doctype):
|
||||||
|
doc_type = doctype.get("doctype")
|
||||||
|
del doctype["doctype"]
|
||||||
|
doc = frappe.get_doc(doc_type, doctype)
|
||||||
|
frappe.delete_doc(doc.doctype, doc.name, ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_company(company):
|
||||||
|
original_company = frappe.db.get_single_value("Global Defaults", "original_default_company")
|
||||||
|
frappe.db.set_single_value("Global Defaults", "default_company", original_company)
|
||||||
|
frappe.delete_doc("Company", company, ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
|
def read_data_file_using_hooks(doctype):
|
||||||
|
path = os.path.join(os.path.dirname(__file__), "demo_data")
|
||||||
|
with open(os.path.join(path, doctype + ".json"), "r") as f:
|
||||||
|
data = f.read()
|
||||||
|
|
||||||
|
return data
|
||||||
|
|||||||
@@ -2,16 +2,19 @@
|
|||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_group": "Demo Customer Group",
|
"customer_group": "Demo Customer Group",
|
||||||
|
"territory": "All Territories",
|
||||||
"customer_name": "ABC Enterprises"
|
"customer_name": "ABC Enterprises"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_group": "Demo Customer Group",
|
"customer_group": "Demo Customer Group",
|
||||||
|
"territory": "All Territories",
|
||||||
"customer_name": "XYZ Corporation"
|
"customer_name": "XYZ Corporation"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_group": "Demo Customer Group",
|
"customer_group": "Demo Customer Group",
|
||||||
|
"territory": "All Territories",
|
||||||
"customer_name": "KJPR Pvt Ltd"
|
"customer_name": "KJPR Pvt Ltd"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Item",
|
"doctype": "Item",
|
||||||
|
"item_group": "Demo Item Group",
|
||||||
"item_code": "SKU006",
|
"item_code": "SKU006",
|
||||||
"item_name": "Coffee Mug",
|
"item_name": "Coffee Mug",
|
||||||
"image": "https://media.istockphoto.com/id/821282266/photo/white-mug-isolated.jpg?s=612x612&w=0&k=20&c=LJCMPk0D83OKmJHahkiLzAB3OsKr83nMbL7KxSgfpfM="
|
"image": "https://media.istockphoto.com/id/821282266/photo/white-mug-isolated.jpg?s=612x612&w=0&k=20&c=LJCMPk0D83OKmJHahkiLzAB3OsKr83nMbL7KxSgfpfM="
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"hide_currency_symbol",
|
"hide_currency_symbol",
|
||||||
"disable_rounded_total",
|
"disable_rounded_total",
|
||||||
"disable_in_words",
|
"disable_in_words",
|
||||||
"demo_company"
|
"original_default_company"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -82,10 +82,10 @@
|
|||||||
"label": "Disable In Words"
|
"label": "Disable In Words"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "demo_company",
|
"fieldname": "original_default_company",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Demo Company",
|
"label": "Original Default Company",
|
||||||
"options": "Company",
|
"options": "Company",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-06-16 13:03:45.016191",
|
"modified": "2023-06-17 13:07:40.074663",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Global Defaults",
|
"name": "Global Defaults",
|
||||||
|
|||||||
Reference in New Issue
Block a user