Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | |
| 3 | import frappe, sys |
| 4 | import erpnext |
| 5 | import frappe.utils |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 6 | from erpnext.demo.user import hr, sales, purchase, manufacturing, stock, accounts, projects, fixed_asset, education |
Rushabh Mehta | f056974 | 2017-09-13 12:52:30 +0530 | [diff] [blame] | 7 | from erpnext.demo.setup import education, manufacture, setup_data, healthcare |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 8 | """ |
| 9 | Make a demo |
| 10 | |
| 11 | 1. Start with a fresh account |
| 12 | |
| 13 | bench --site demo.erpnext.dev reinstall |
| 14 | |
| 15 | 2. Install Demo |
| 16 | |
| 17 | bench --site demo.erpnext.dev execute erpnext.demo.demo.make |
| 18 | |
| 19 | 3. If Demo breaks, to continue |
| 20 | |
| 21 | bench --site demo.erpnext.dev execute erpnext.demo.demo.simulate |
| 22 | |
| 23 | """ |
| 24 | |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 25 | def make(domain='Manufacturing', days=100): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 26 | frappe.flags.domain = domain |
Rushabh Mehta | b814a54 | 2016-07-13 18:17:19 +0530 | [diff] [blame] | 27 | frappe.flags.mute_emails = True |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 28 | setup_data.setup(domain) |
| 29 | if domain== 'Manufacturing': |
| 30 | manufacture.setup_data() |
| 31 | elif domain== 'Education': |
| 32 | education.setup_data() |
Rushabh Mehta | f056974 | 2017-09-13 12:52:30 +0530 | [diff] [blame] | 33 | elif domain== 'Healthcare': |
| 34 | healthcare.setup_data() |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 35 | |
Rushabh Mehta | ffa70e3 | 2016-07-13 17:41:03 +0530 | [diff] [blame] | 36 | site = frappe.local.site |
| 37 | frappe.destroy() |
| 38 | frappe.init(site) |
| 39 | frappe.connect() |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 40 | |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 41 | simulate(domain, days) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 42 | |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 43 | def simulate(domain='Manufacturing', days=100): |
| 44 | runs_for = frappe.flags.runs_for or days |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 45 | frappe.flags.company = erpnext.get_default_company() |
Rushabh Mehta | b814a54 | 2016-07-13 18:17:19 +0530 | [diff] [blame] | 46 | frappe.flags.mute_emails = True |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 47 | |
| 48 | if not frappe.flags.start_date: |
| 49 | # start date = 100 days back |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 50 | frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(), |
| 51 | -1 * runs_for) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 52 | |
| 53 | current_date = frappe.utils.getdate(frappe.flags.start_date) |
| 54 | |
| 55 | # continue? |
| 56 | demo_last_date = frappe.db.get_global('demo_last_date') |
| 57 | if demo_last_date: |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 58 | current_date = frappe.utils.add_days(frappe.utils.getdate(demo_last_date), 1) |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 59 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 60 | # run till today |
| 61 | if not runs_for: |
| 62 | runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date) |
| 63 | # runs_for = 100 |
Rushabh Mehta | 06c92a7 | 2016-08-03 16:27:11 +0530 | [diff] [blame] | 64 | |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 65 | fixed_asset.work() |
Achilles Rasquinha | 96698c9 | 2018-02-28 16:12:51 +0530 | [diff] [blame] | 66 | for i in range(runs_for): |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 67 | sys.stdout.write("\rSimulating {0}: Day {1}".format( |
| 68 | current_date.strftime("%Y-%m-%d"), i)) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 69 | sys.stdout.flush() |
| 70 | frappe.flags.current_date = current_date |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 71 | if current_date.weekday() in (5, 6): |
| 72 | current_date = frappe.utils.add_days(current_date, 1) |
| 73 | continue |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 74 | try: |
| 75 | hr.work() |
| 76 | purchase.work() |
| 77 | stock.work() |
| 78 | accounts.work() |
| 79 | projects.run_projects(current_date) |
Manas Solanki | f60bd60 | 2017-06-01 18:30:35 +0530 | [diff] [blame] | 80 | # run_messages() |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 81 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 82 | if domain=='Manufacturing': |
| 83 | sales.work() |
| 84 | manufacturing.work() |
| 85 | elif domain=='Education': |
Manas Solanki | 966f141 | 2017-11-23 15:22:10 +0530 | [diff] [blame] | 86 | education.work() |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 87 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 88 | except: |
| 89 | frappe.db.set_global('demo_last_date', current_date) |
Rushabh Mehta | 99c814b | 2016-12-19 11:51:02 +0530 | [diff] [blame] | 90 | raise |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 91 | finally: |
| 92 | current_date = frappe.utils.add_days(current_date, 1) |
| 93 | frappe.db.commit() |