2016-06-29 13:08:32 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import sys
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2016-06-29 13:08:32 +00:00
|
|
|
import frappe
|
|
|
|
import frappe.utils
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-10-01 05:17:29 +00:00
|
|
|
import erpnext
|
2021-09-02 14:27:43 +00:00
|
|
|
from erpnext.demo.setup import education, manufacture, retail, setup_data
|
2018-10-01 05:17:29 +00:00
|
|
|
from erpnext.demo.user import accounts
|
|
|
|
from erpnext.demo.user import education as edu
|
2018-10-10 08:57:07 +00:00
|
|
|
from erpnext.demo.user import fixed_asset, hr, manufacturing, projects, purchase, sales, stock
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2016-07-13 05:59:59 +00:00
|
|
|
"""
|
|
|
|
Make a demo
|
|
|
|
|
|
|
|
1. Start with a fresh account
|
|
|
|
|
|
|
|
bench --site demo.erpnext.dev reinstall
|
|
|
|
|
|
|
|
2. Install Demo
|
|
|
|
|
|
|
|
bench --site demo.erpnext.dev execute erpnext.demo.demo.make
|
|
|
|
|
|
|
|
3. If Demo breaks, to continue
|
|
|
|
|
|
|
|
bench --site demo.erpnext.dev execute erpnext.demo.demo.simulate
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2017-06-12 03:48:06 +00:00
|
|
|
def make(domain='Manufacturing', days=100):
|
2016-06-29 13:08:32 +00:00
|
|
|
frappe.flags.domain = domain
|
2016-07-13 12:47:19 +00:00
|
|
|
frappe.flags.mute_emails = True
|
2016-08-22 07:27:09 +00:00
|
|
|
setup_data.setup(domain)
|
|
|
|
if domain== 'Manufacturing':
|
|
|
|
manufacture.setup_data()
|
2018-10-10 08:57:07 +00:00
|
|
|
elif domain == "Retail":
|
|
|
|
retail.setup_data()
|
2016-08-22 07:27:09 +00:00
|
|
|
elif domain== 'Education':
|
|
|
|
education.setup_data()
|
2016-12-19 06:21:02 +00:00
|
|
|
|
2016-07-13 12:11:03 +00:00
|
|
|
site = frappe.local.site
|
|
|
|
frappe.destroy()
|
|
|
|
frappe.init(site)
|
|
|
|
frappe.connect()
|
2017-06-01 13:00:35 +00:00
|
|
|
|
2017-06-12 03:48:06 +00:00
|
|
|
simulate(domain, days)
|
2016-06-29 13:08:32 +00:00
|
|
|
|
2017-06-12 03:48:06 +00:00
|
|
|
def simulate(domain='Manufacturing', days=100):
|
|
|
|
runs_for = frappe.flags.runs_for or days
|
2016-06-29 13:08:32 +00:00
|
|
|
frappe.flags.company = erpnext.get_default_company()
|
2016-07-13 12:47:19 +00:00
|
|
|
frappe.flags.mute_emails = True
|
2016-06-29 13:08:32 +00:00
|
|
|
|
|
|
|
if not frappe.flags.start_date:
|
|
|
|
# start date = 100 days back
|
2017-06-12 03:48:06 +00:00
|
|
|
frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(),
|
|
|
|
-1 * runs_for)
|
2016-06-29 13:08:32 +00:00
|
|
|
|
|
|
|
current_date = frappe.utils.getdate(frappe.flags.start_date)
|
|
|
|
|
|
|
|
# continue?
|
|
|
|
demo_last_date = frappe.db.get_global('demo_last_date')
|
|
|
|
if demo_last_date:
|
2016-08-22 07:27:09 +00:00
|
|
|
current_date = frappe.utils.add_days(frappe.utils.getdate(demo_last_date), 1)
|
2016-12-19 06:21:02 +00:00
|
|
|
|
2016-06-29 13:08:32 +00:00
|
|
|
# run till today
|
|
|
|
if not runs_for:
|
|
|
|
runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date)
|
|
|
|
# runs_for = 100
|
2016-08-03 10:57:11 +00:00
|
|
|
|
2016-07-20 10:43:18 +00:00
|
|
|
fixed_asset.work()
|
2018-02-28 10:42:51 +00:00
|
|
|
for i in range(runs_for):
|
2016-12-19 06:21:02 +00:00
|
|
|
sys.stdout.write("\rSimulating {0}: Day {1}".format(
|
|
|
|
current_date.strftime("%Y-%m-%d"), i))
|
2016-06-29 13:08:32 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
frappe.flags.current_date = current_date
|
|
|
|
if current_date.weekday() in (5, 6):
|
|
|
|
current_date = frappe.utils.add_days(current_date, 1)
|
|
|
|
continue
|
2016-08-22 07:27:09 +00:00
|
|
|
try:
|
|
|
|
hr.work()
|
|
|
|
purchase.work()
|
|
|
|
stock.work()
|
|
|
|
accounts.work()
|
|
|
|
projects.run_projects(current_date)
|
2018-10-10 08:57:07 +00:00
|
|
|
sales.work(domain)
|
2017-06-01 13:00:35 +00:00
|
|
|
# run_messages()
|
2016-12-19 06:21:02 +00:00
|
|
|
|
2016-08-22 07:27:09 +00:00
|
|
|
if domain=='Manufacturing':
|
|
|
|
manufacturing.work()
|
|
|
|
elif domain=='Education':
|
2018-10-01 05:17:29 +00:00
|
|
|
edu.work()
|
2016-12-19 06:21:02 +00:00
|
|
|
|
2021-09-01 09:10:56 +00:00
|
|
|
except Exception:
|
2016-08-22 07:27:09 +00:00
|
|
|
frappe.db.set_global('demo_last_date', current_date)
|
2016-12-19 06:21:02 +00:00
|
|
|
raise
|
2016-08-22 07:27:09 +00:00
|
|
|
finally:
|
|
|
|
current_date = frappe.utils.add_days(current_date, 1)
|
|
|
|
frappe.db.commit()
|