brotherton-erpnext/erpnext/demo/demo.py

81 lines
1.9 KiB
Python
Raw Normal View History

2016-06-29 13:08:32 +00:00
from __future__ import unicode_literals
import frappe, sys
import erpnext
import frappe.utils
from erpnext.demo.setup_data import setup_data
2016-07-13 10:33:05 +00:00
from erpnext.demo.user import hr, sales, purchase, manufacturing, stock, accounts, projects
2016-06-29 13:08:32 +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
"""
2016-06-29 13:08:32 +00:00
def make(domain='Manufacturing'):
frappe.flags.domain = domain
2016-07-13 12:47:19 +00:00
frappe.flags.mute_emails = True
2016-06-29 13:08:32 +00:00
setup_data()
2016-07-13 12:11:03 +00:00
site = frappe.local.site
frappe.destroy()
frappe.init(site)
frappe.connect()
2016-06-29 13:08:32 +00:00
simulate()
def simulate():
runs_for = frappe.flags.runs_for or 150
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
frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(), -1 * runs_for)
current_date = frappe.utils.getdate(frappe.flags.start_date)
# continue?
demo_last_date = frappe.db.get_global('demo_last_date')
if demo_last_date:
current_date = frappe.utils.add_days(demo_last_date, 1)
# run till today
if not runs_for:
runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date)
# runs_for = 100
for i in xrange(runs_for):
sys.stdout.write("\rSimulating {0}".format(current_date.strftime("%Y-%m-%d")))
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
hr.work()
sales.work()
2016-07-07 08:32:26 +00:00
purchase.work()
2016-07-08 12:54:46 +00:00
manufacturing.work()
stock.work()
accounts.work()
2016-07-13 10:33:05 +00:00
projects.run_projects(current_date)
# run_stock()
# run_accounts()
2016-06-29 13:08:32 +00:00
# run_projects()
# run_messages()
current_date = frappe.utils.add_days(current_date, 1)
frappe.db.commit()