fix: Button to clear demo data
diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js
index d7bea7b..966a9e1 100644
--- a/erpnext/public/js/erpnext.bundle.js
+++ b/erpnext/public/js/erpnext.bundle.js
@@ -28,5 +28,6 @@
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 432bad6..22d78d8 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 = $(`
+ <div class="flex justify-content-center" style="width: 100%;">
+ <div class="flex justify-content-center flex-col shadow rounded p-2"
+ style="
+ width: 50%;
+ background-color: #e0f2fe;
+ position: fixed;
+ bottom: 20px;
+ z-index: 1;">
+ <p style="margin: auto 0; padding-left: 10px; margin-right: 20px; font-size: 15px;">
+ ${message_string}
+ </p>
+ <button id="clear-demo" type="button"
+ class="
+ px-4
+ py-2
+ border
+ border-transparent
+ text-white
+ "
+ style="
+ margin: auto 0;
+ height: fit-content;
+ background-color: #007bff;
+ border-radius: 5px;
+ margin-right: 10px
+ "
+ >
+ Clear
+ </button>
+ </div>
+ </div>
+ `);
+
+ $('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 882ed37..b8cdc05 100644
--- a/erpnext/setup/demo.py
+++ b/erpnext/setup/demo.py
@@ -6,9 +6,10 @@
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 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 db1cc49..bdbf8b4 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -61,6 +61,8 @@
)
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(