fix: Button to clear demo data
This commit is contained in:
parent
3698af834b
commit
371413a078
@ -28,5 +28,6 @@ import "./controllers/accounts.js"
|
|||||||
import "./utils/landed_taxes_and_charges_common.js";
|
import "./utils/landed_taxes_and_charges_common.js";
|
||||||
import "./utils/sales_common.js";
|
import "./utils/sales_common.js";
|
||||||
import "./controllers/buying.js";
|
import "./controllers/buying.js";
|
||||||
|
import "./utils/demo.js";
|
||||||
|
|
||||||
// import { sum } from 'frappe/public/utils/util.js'
|
// import { sum } from 'frappe/public/utils/util.js'
|
||||||
|
|||||||
@ -1,11 +1,57 @@
|
|||||||
$(document).on("toolbar_setup", function() {
|
$(document).on("toolbar_setup", function() {
|
||||||
if (erpnext.is_demo_company_setup) {
|
if (frappe.boot.sysdefaults.demo_company) {
|
||||||
console.log("setup");
|
erpnext.setup_clear_button();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.is_demo_company_setup = function() {
|
erpnext.setup_clear_button = function() {
|
||||||
frappe.db.get_value("Global Default", "Global Default", "demo_company", function(r) {
|
let message_string = __('Demo data is setup, use this button to clear before starting actual transactions');
|
||||||
console.log(r);
|
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);
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
@ -6,9 +6,10 @@ import os
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import add_days
|
from frappe.utils import add_days, getdate
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
from erpnext.setup.setup_wizard.operations.install_fixtures import create_bank_account
|
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):
|
def make_transactions(company):
|
||||||
fiscal_year = frappe.db.get_single_value("Global Defaults", "current_fiscal_year")
|
start_date = get_fiscal_year(date=getdate())[1]
|
||||||
start_date = frappe.db.get_value("Fiscal Year", fiscal_year, "year_start_date")
|
|
||||||
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
||||||
|
|
||||||
for doctype in frappe.get_hooks("demo_transaction_doctypes"):
|
for doctype in frappe.get_hooks("demo_transaction_doctypes"):
|
||||||
|
|||||||
@ -61,6 +61,8 @@ def boot_session(bootinfo):
|
|||||||
)
|
)
|
||||||
bootinfo.party_account_types = frappe._dict(party_account_types)
|
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):
|
def update_page_info(bootinfo):
|
||||||
bootinfo.page_info.update(
|
bootinfo.page_info.update(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user