blob: 12fad296723604a5ed2bcc2518a8afea83aa2f1d [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
7from frappe.utils.make_random import can_make
8from frappe.utils.make_random import how_many, get_random
9from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
10
11def run_projects(current_date):
12 frappe.set_user(frappe.db.get_global('demo_projects_user'))
13 if frappe.db.get_global('demo_projects_user'):
14 make_project(current_date)
15 make_timesheet_for_projects(current_date)
16 close_tasks(current_date)
17
18def make_timesheet_for_projects(current_date ):
19 for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}):
20 employee = get_random("Employee")
21 if frappe.db.get_value('Salary Structure', {'employee': employee}, 'salary_slip_based_on_timesheet'):
22 make_timesheet(employee, simulate = True, billable = 1,
23 activity_type=get_random("Activity Type"), project=data.project, task =data.name)
24
25def close_tasks(current_date):
26 for task in frappe.get_all("Task", ["name"], {"status": "Open", "exp_end_date": ("<", current_date)}):
27 task = frappe.get_doc("Task", task.name)
28 task.status = "Closed"
29 task.save()
30
31def make_project(current_date):
32 if not frappe.db.exists('Project',
33 "New Product Development " + current_date.strftime("%Y-%m-%d")):
34 project = frappe.get_doc({
35 "doctype": "Project",
36 "project_name": "New Product Development " + current_date.strftime("%Y-%m-%d"),
37 })
38 project.set("tasks", [
39 {
40 "title": "Review Requirements",
41 "start_date": frappe.utils.add_days(current_date, 10),
42 "end_date": frappe.utils.add_days(current_date, 11)
43 },
44 {
45 "title": "Design Options",
46 "start_date": frappe.utils.add_days(current_date, 11),
47 "end_date": frappe.utils.add_days(current_date, 20)
48 },
49 {
50 "title": "Make Prototypes",
51 "start_date": frappe.utils.add_days(current_date, 20),
52 "end_date": frappe.utils.add_days(current_date, 30)
53 },
54 {
55 "title": "Customer Feedback on Prototypes",
56 "start_date": frappe.utils.add_days(current_date, 30),
57 "end_date": frappe.utils.add_days(current_date, 40)
58 },
59 {
60 "title": "Freeze Feature Set",
61 "start_date": frappe.utils.add_days(current_date, 40),
62 "end_date": frappe.utils.add_days(current_date, 45)
63 },
64 {
65 "title": "Testing",
66 "start_date": frappe.utils.add_days(current_date, 45),
67 "end_date": frappe.utils.add_days(current_date, 60)
68 },
69 {
70 "title": "Product Engineering",
71 "start_date": frappe.utils.add_days(current_date, 45),
72 "end_date": frappe.utils.add_days(current_date, 55)
73 },
74 {
75 "title": "Supplier Contracts",
76 "start_date": frappe.utils.add_days(current_date, 55),
77 "end_date": frappe.utils.add_days(current_date, 70)
78 },
79 {
80 "title": "Design and Build Fixtures",
81 "start_date": frappe.utils.add_days(current_date, 45),
82 "end_date": frappe.utils.add_days(current_date, 65)
83 },
84 {
85 "title": "Test Run",
86 "start_date": frappe.utils.add_days(current_date, 70),
87 "end_date": frappe.utils.add_days(current_date, 80)
88 },
89 {
90 "title": "Launch",
91 "start_date": frappe.utils.add_days(current_date, 80),
92 "end_date": frappe.utils.add_days(current_date, 90)
93 },
94 ])
95 project.insert()