blob: 9802447679359c8c2c306a88c432a13d66d89bbe [file] [log] [blame]
Rohit Waghchaure8002d472016-07-13 16:03:05 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5
6import frappe
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +05307from frappe.utils import flt
Neil Trini Lasrado06724592016-08-22 12:57:09 +05308from frappe.utils.make_random import get_random
Rohit Waghchaure8002d472016-07-13 16:03:05 +05309from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +053010from erpnext.demo.user.hr import make_sales_invoice_for_timesheet
Rohit Waghchaure8002d472016-07-13 16:03:05 +053011
12def 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
19def 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")
Neil Trini Lasrado06724592016-08-22 12:57:09 +053022 ts = make_timesheet(employee, simulate = True, billable = 1,
23 activity_type=get_random("Activity Type"), project=data.project, task =data.name)
Rohit Waghchaure8002d472016-07-13 16:03:05 +053024
Rohit Waghchaure7b6fdb72016-09-12 19:06:41 +053025 if flt(ts.total_billable_amount) > 0.0:
Neil Trini Lasrado06724592016-08-22 12:57:09 +053026 make_sales_invoice_for_timesheet(ts.name)
27 frappe.db.commit()
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +053028
Rohit Waghchaure8002d472016-07-13 16:03:05 +053029def 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
35def 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()