blob: 8cafd402f761ed7c47860d1d9438781f069fbae3 [file] [log] [blame]
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05301from __future__ import unicode_literals
2
3import frappe, sys
4import erpnext
5import frappe.utils
Zlash65e8958452018-10-01 10:47:29 +05306from erpnext.demo.user import hr, sales, purchase, manufacturing, stock, accounts, projects, fixed_asset
7from erpnext.demo.user import education as edu
Rushabh Mehtaf0569742017-09-13 12:52:30 +05308from erpnext.demo.setup import education, manufacture, setup_data, healthcare
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +05309"""
10Make a demo
11
121. Start with a fresh account
13
14bench --site demo.erpnext.dev reinstall
15
162. Install Demo
17
18bench --site demo.erpnext.dev execute erpnext.demo.demo.make
19
203. If Demo breaks, to continue
21
22bench --site demo.erpnext.dev execute erpnext.demo.demo.simulate
23
24"""
25
Rushabh Mehta4f8f9c12017-06-12 09:18:06 +053026def make(domain='Manufacturing', days=100):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053027 frappe.flags.domain = domain
Rushabh Mehtab814a542016-07-13 18:17:19 +053028 frappe.flags.mute_emails = True
Neil Trini Lasrado06724592016-08-22 12:57:09 +053029 setup_data.setup(domain)
30 if domain== 'Manufacturing':
31 manufacture.setup_data()
32 elif domain== 'Education':
33 education.setup_data()
Rushabh Mehtaf0569742017-09-13 12:52:30 +053034 elif domain== 'Healthcare':
35 healthcare.setup_data()
Rushabh Mehta99c814b2016-12-19 11:51:02 +053036
Rushabh Mehtaffa70e32016-07-13 17:41:03 +053037 site = frappe.local.site
38 frappe.destroy()
39 frappe.init(site)
40 frappe.connect()
Manas Solankif60bd602017-06-01 18:30:35 +053041
Rushabh Mehta4f8f9c12017-06-12 09:18:06 +053042 simulate(domain, days)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053043
Rushabh Mehta4f8f9c12017-06-12 09:18:06 +053044def simulate(domain='Manufacturing', days=100):
45 runs_for = frappe.flags.runs_for or days
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053046 frappe.flags.company = erpnext.get_default_company()
Rushabh Mehtab814a542016-07-13 18:17:19 +053047 frappe.flags.mute_emails = True
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053048
49 if not frappe.flags.start_date:
50 # start date = 100 days back
Rushabh Mehta4f8f9c12017-06-12 09:18:06 +053051 frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(),
52 -1 * runs_for)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053053
54 current_date = frappe.utils.getdate(frappe.flags.start_date)
55
56 # continue?
57 demo_last_date = frappe.db.get_global('demo_last_date')
58 if demo_last_date:
Neil Trini Lasrado06724592016-08-22 12:57:09 +053059 current_date = frappe.utils.add_days(frappe.utils.getdate(demo_last_date), 1)
Rushabh Mehta99c814b2016-12-19 11:51:02 +053060
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053061 # run till today
62 if not runs_for:
63 runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date)
64 # runs_for = 100
Rushabh Mehta06c92a72016-08-03 16:27:11 +053065
Nabin Hait3edefb12016-07-20 16:13:18 +053066 fixed_asset.work()
Achilles Rasquinha96698c92018-02-28 16:12:51 +053067 for i in range(runs_for):
Rushabh Mehta99c814b2016-12-19 11:51:02 +053068 sys.stdout.write("\rSimulating {0}: Day {1}".format(
69 current_date.strftime("%Y-%m-%d"), i))
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053070 sys.stdout.flush()
71 frappe.flags.current_date = current_date
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053072 if current_date.weekday() in (5, 6):
73 current_date = frappe.utils.add_days(current_date, 1)
74 continue
Neil Trini Lasrado06724592016-08-22 12:57:09 +053075 try:
76 hr.work()
77 purchase.work()
78 stock.work()
79 accounts.work()
80 projects.run_projects(current_date)
Manas Solankif60bd602017-06-01 18:30:35 +053081 # run_messages()
Rushabh Mehta99c814b2016-12-19 11:51:02 +053082
Neil Trini Lasrado06724592016-08-22 12:57:09 +053083 if domain=='Manufacturing':
84 sales.work()
85 manufacturing.work()
86 elif domain=='Education':
Zlash65e8958452018-10-01 10:47:29 +053087 edu.work()
Rushabh Mehta99c814b2016-12-19 11:51:02 +053088
Neil Trini Lasrado06724592016-08-22 12:57:09 +053089 except:
90 frappe.db.set_global('demo_last_date', current_date)
Rushabh Mehta99c814b2016-12-19 11:51:02 +053091 raise
Neil Trini Lasrado06724592016-08-22 12:57:09 +053092 finally:
93 current_date = frappe.utils.add_days(current_date, 1)
94 frappe.db.commit()