diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js
index d7bea7b8341..966a9e1f9b3 100644
--- a/erpnext/public/js/erpnext.bundle.js
+++ b/erpnext/public/js/erpnext.bundle.js
@@ -28,5 +28,6 @@ import "./controllers/accounts.js"
import "./utils/landed_taxes_and_charges_common.js";
import "./utils/sales_common.js";
import "./controllers/buying.js";
+import "./utils/demo.js";
// import { sum } from 'frappe/public/utils/util.js'
diff --git a/erpnext/public/js/utils/demo.js b/erpnext/public/js/utils/demo.js
index 432bad63239..22d78d8c67c 100644
--- a/erpnext/public/js/utils/demo.js
+++ b/erpnext/public/js/utils/demo.js
@@ -1,11 +1,57 @@
$(document).on("toolbar_setup", function() {
- if (erpnext.is_demo_company_setup) {
- console.log("setup");
- }
+ if (frappe.boot.sysdefaults.demo_company) {
+ erpnext.setup_clear_button();
+ }
});
-erpnext.is_demo_company_setup = function() {
- frappe.db.get_value("Global Default", "Global Default", "demo_company", function(r) {
- console.log(r);
- });
-};
\ No newline at end of file
+erpnext.setup_clear_button = function() {
+ let message_string = __('Demo data is setup, use this button to clear before starting actual transactions');
+ let $floatingBar = $(`
+
+
+
+ ${message_string}
+
+
+
+
+ `);
+
+ $('footer').append($floatingBar);
+
+ $('#clear-demo').on('click', function () {
+ frappe.call({
+ method: "erpnext.setup.demo.clear_demo_data",
+ freeze: true,
+ freeze_message: __('Clearing Demo Data...'),
+ callback: function(r) {
+ frappe.ui.toolbar.clear_cache();
+ frappe.show_alert({ message: __('Demo data cleared'), indicator: 'green' });
+ $('footer').remove($floatingBar);
+ }
+ })
+ });
+}
\ No newline at end of file
diff --git a/erpnext/setup/demo.py b/erpnext/setup/demo.py
index 882ed37a92c..b8cdc05dd3e 100644
--- a/erpnext/setup/demo.py
+++ b/erpnext/setup/demo.py
@@ -6,9 +6,10 @@ import os
from random import randint
import frappe
-from frappe.utils import add_days
+from frappe.utils import add_days, getdate
import erpnext
+from erpnext.accounts.utils import get_fiscal_year
from erpnext.setup.setup_wizard.operations.install_fixtures import create_bank_account
@@ -65,8 +66,7 @@ def create_demo_record(doctype):
def make_transactions(company):
- fiscal_year = frappe.db.get_single_value("Global Defaults", "current_fiscal_year")
- start_date = frappe.db.get_value("Fiscal Year", fiscal_year, "year_start_date")
+ start_date = get_fiscal_year(date=getdate())[1]
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
for doctype in frappe.get_hooks("demo_transaction_doctypes"):
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index db1cc494e0b..bdbf8b4fac5 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -61,6 +61,8 @@ def boot_session(bootinfo):
)
bootinfo.party_account_types = frappe._dict(party_account_types)
+ bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company")
+
def update_page_info(bootinfo):
bootinfo.page_info.update(