blob: 044e2967fdec5bee4edb087155ae541a6e9c46e2 [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
Zlash65dcf74012018-09-27 18:51:18 +05306import frappe, erpnext
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")
Zlash65dcf74012018-09-27 18:51:18 +053022 ts = make_timesheet(employee, simulate = True, billable = 1, company = erpnext.get_default_company(),
Neil Trini Lasrado06724592016-08-22 12:57:09 +053023 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)
Rushabh Mehta02a9ec32019-02-19 14:38:03 +053032 task.status = "Completed"
Rohit Waghchaure8002d472016-07-13 16:03:05 +053033 task.save()
34
35def make_project(current_date):
Rushabh Mehta02a9ec32019-02-19 14:38:03 +053036 if not frappe.db.exists('Project',
Rohit Waghchaure8002d472016-07-13 16:03:05 +053037 "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 })
Rohit Waghchaure8002d472016-07-13 16:03:05 +053042 project.insert()