brotherton-erpnext/erpnext/demo/user/projects.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.6 KiB
Python
Raw Normal View History

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
2018-09-27 13:21:18 +00:00
import frappe
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
import erpnext
from erpnext.demo.user.hr import make_sales_invoice_for_timesheet
2016-07-13 10:33:05 +00:00
from erpnext.projects.doctype.timesheet.test_timesheet import make_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
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-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)
task.status = "Completed"
2016-07-13 10:33:05 +00:00
task.save()
def make_project(current_date):
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.insert()