2016-07-13 10:33:05 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-09-27 13:21:18 +00:00
|
|
|
import frappe, erpnext
|
2016-07-21 09:20:59 +00:00
|
|
|
from frappe.utils import flt
|
2016-08-22 07:27:09 +00:00
|
|
|
from frappe.utils.make_random import get_random
|
2016-07-13 10:33:05 +00:00
|
|
|
from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
|
2016-07-21 09:20:59 +00:00
|
|
|
from erpnext.demo.user.hr import make_sales_invoice_for_timesheet
|
2016-07-13 10:33:05 +00:00
|
|
|
|
|
|
|
def run_projects(current_date):
|
|
|
|
frappe.set_user(frappe.db.get_global('demo_projects_user'))
|
|
|
|
if frappe.db.get_global('demo_projects_user'):
|
|
|
|
make_project(current_date)
|
|
|
|
make_timesheet_for_projects(current_date)
|
|
|
|
close_tasks(current_date)
|
|
|
|
|
|
|
|
def make_timesheet_for_projects(current_date ):
|
|
|
|
for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}):
|
|
|
|
employee = get_random("Employee")
|
2018-09-27 13:21:18 +00:00
|
|
|
ts = make_timesheet(employee, simulate = True, billable = 1, company = erpnext.get_default_company(),
|
2016-08-22 07:27:09 +00:00
|
|
|
activity_type=get_random("Activity Type"), project=data.project, task =data.name)
|
2016-07-13 10:33:05 +00:00
|
|
|
|
2016-09-12 13:36:41 +00:00
|
|
|
if flt(ts.total_billable_amount) > 0.0:
|
2016-08-22 07:27:09 +00:00
|
|
|
make_sales_invoice_for_timesheet(ts.name)
|
|
|
|
frappe.db.commit()
|
2016-07-21 09:20:59 +00:00
|
|
|
|
2016-07-13 10:33:05 +00:00
|
|
|
def close_tasks(current_date):
|
|
|
|
for task in frappe.get_all("Task", ["name"], {"status": "Open", "exp_end_date": ("<", current_date)}):
|
|
|
|
task = frappe.get_doc("Task", task.name)
|
2019-02-19 09:08:03 +00:00
|
|
|
task.status = "Completed"
|
2016-07-13 10:33:05 +00:00
|
|
|
task.save()
|
|
|
|
|
|
|
|
def make_project(current_date):
|
2019-02-19 09:08:03 +00:00
|
|
|
if not frappe.db.exists('Project',
|
2016-07-13 10:33:05 +00:00
|
|
|
"New Product Development " + current_date.strftime("%Y-%m-%d")):
|
|
|
|
project = frappe.get_doc({
|
|
|
|
"doctype": "Project",
|
|
|
|
"project_name": "New Product Development " + current_date.strftime("%Y-%m-%d"),
|
|
|
|
})
|
|
|
|
project.set("tasks", [
|
|
|
|
{
|
|
|
|
"title": "Review Requirements",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 10),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 11)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Design Options",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 11),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 20)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Make Prototypes",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 20),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 30)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Customer Feedback on Prototypes",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 30),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 40)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Freeze Feature Set",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 40),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 45)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Testing",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 45),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 60)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Product Engineering",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 45),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 55)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Supplier Contracts",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 55),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 70)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Design and Build Fixtures",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 45),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 65)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Test Run",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 70),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 80)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Launch",
|
|
|
|
"start_date": frappe.utils.add_days(current_date, 80),
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 90)
|
|
|
|
},
|
|
|
|
])
|
|
|
|
project.insert()
|