Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | |
Zlash65 | dcf7401 | 2018-09-27 18:51:18 +0530 | [diff] [blame] | 6 | import frappe, erpnext |
Rohit Waghchaure | 7d439ec | 2016-07-21 14:50:59 +0530 | [diff] [blame] | 7 | from frappe.utils import flt |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 8 | from frappe.utils.make_random import get_random |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 9 | from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet |
Rohit Waghchaure | 7d439ec | 2016-07-21 14:50:59 +0530 | [diff] [blame] | 10 | from erpnext.demo.user.hr import make_sales_invoice_for_timesheet |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 11 | |
| 12 | def run_projects(current_date): |
| 13 | frappe.set_user(frappe.db.get_global('demo_projects_user')) |
| 14 | if frappe.db.get_global('demo_projects_user'): |
| 15 | make_project(current_date) |
| 16 | make_timesheet_for_projects(current_date) |
| 17 | close_tasks(current_date) |
| 18 | |
| 19 | def make_timesheet_for_projects(current_date ): |
| 20 | for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}): |
| 21 | employee = get_random("Employee") |
Zlash65 | dcf7401 | 2018-09-27 18:51:18 +0530 | [diff] [blame] | 22 | ts = make_timesheet(employee, simulate = True, billable = 1, company = erpnext.get_default_company(), |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 23 | activity_type=get_random("Activity Type"), project=data.project, task =data.name) |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 24 | |
Rohit Waghchaure | 7b6fdb7 | 2016-09-12 19:06:41 +0530 | [diff] [blame] | 25 | if flt(ts.total_billable_amount) > 0.0: |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 26 | make_sales_invoice_for_timesheet(ts.name) |
| 27 | frappe.db.commit() |
Rohit Waghchaure | 7d439ec | 2016-07-21 14:50:59 +0530 | [diff] [blame] | 28 | |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 29 | def close_tasks(current_date): |
| 30 | for task in frappe.get_all("Task", ["name"], {"status": "Open", "exp_end_date": ("<", current_date)}): |
| 31 | task = frappe.get_doc("Task", task.name) |
| 32 | task.status = "Closed" |
| 33 | task.save() |
| 34 | |
| 35 | def make_project(current_date): |
| 36 | if not frappe.db.exists('Project', |
| 37 | "New Product Development " + current_date.strftime("%Y-%m-%d")): |
| 38 | project = frappe.get_doc({ |
| 39 | "doctype": "Project", |
| 40 | "project_name": "New Product Development " + current_date.strftime("%Y-%m-%d"), |
| 41 | }) |
| 42 | project.set("tasks", [ |
| 43 | { |
| 44 | "title": "Review Requirements", |
| 45 | "start_date": frappe.utils.add_days(current_date, 10), |
| 46 | "end_date": frappe.utils.add_days(current_date, 11) |
| 47 | }, |
| 48 | { |
| 49 | "title": "Design Options", |
| 50 | "start_date": frappe.utils.add_days(current_date, 11), |
| 51 | "end_date": frappe.utils.add_days(current_date, 20) |
| 52 | }, |
| 53 | { |
| 54 | "title": "Make Prototypes", |
| 55 | "start_date": frappe.utils.add_days(current_date, 20), |
| 56 | "end_date": frappe.utils.add_days(current_date, 30) |
| 57 | }, |
| 58 | { |
| 59 | "title": "Customer Feedback on Prototypes", |
| 60 | "start_date": frappe.utils.add_days(current_date, 30), |
| 61 | "end_date": frappe.utils.add_days(current_date, 40) |
| 62 | }, |
| 63 | { |
| 64 | "title": "Freeze Feature Set", |
| 65 | "start_date": frappe.utils.add_days(current_date, 40), |
| 66 | "end_date": frappe.utils.add_days(current_date, 45) |
| 67 | }, |
| 68 | { |
| 69 | "title": "Testing", |
| 70 | "start_date": frappe.utils.add_days(current_date, 45), |
| 71 | "end_date": frappe.utils.add_days(current_date, 60) |
| 72 | }, |
| 73 | { |
| 74 | "title": "Product Engineering", |
| 75 | "start_date": frappe.utils.add_days(current_date, 45), |
| 76 | "end_date": frappe.utils.add_days(current_date, 55) |
| 77 | }, |
| 78 | { |
| 79 | "title": "Supplier Contracts", |
| 80 | "start_date": frappe.utils.add_days(current_date, 55), |
| 81 | "end_date": frappe.utils.add_days(current_date, 70) |
| 82 | }, |
| 83 | { |
| 84 | "title": "Design and Build Fixtures", |
| 85 | "start_date": frappe.utils.add_days(current_date, 45), |
| 86 | "end_date": frappe.utils.add_days(current_date, 65) |
| 87 | }, |
| 88 | { |
| 89 | "title": "Test Run", |
| 90 | "start_date": frappe.utils.add_days(current_date, 70), |
| 91 | "end_date": frappe.utils.add_days(current_date, 80) |
| 92 | }, |
| 93 | { |
| 94 | "title": "Launch", |
| 95 | "start_date": frappe.utils.add_days(current_date, 80), |
| 96 | "end_date": frappe.utils.add_days(current_date, 90) |
| 97 | }, |
| 98 | ]) |
| 99 | project.insert() |