Fixes in Project

This commit is contained in:
Neil Trini Lasrado 2015-04-10 14:44:41 +05:30
parent 78b96ca769
commit 650e679a5e
3 changed files with 7 additions and 18 deletions

View File

@ -131,7 +131,7 @@
"options": "Project Task", "options": "Project Task",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"reqd": 0 "reqd": 1
}, },
{ {
"fieldname": "percent_complete", "fieldname": "percent_complete",
@ -279,7 +279,7 @@
"icon": "icon-puzzle-piece", "icon": "icon-puzzle-piece",
"idx": 1, "idx": 1,
"max_attachments": 4, "max_attachments": 4,
"modified": "2015-03-31 06:12:03.372091", "modified": "2015-04-10 05:11:18.849171",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Projects", "module": "Projects",
"name": "Project", "name": "Project",

View File

@ -35,17 +35,12 @@ class Project(Document):
def validate(self): def validate(self):
self.validate_dates() self.validate_dates()
self.validate_tasks()
self.sync_tasks() self.sync_tasks()
def validate_dates(self): def validate_dates(self):
if self.project_start_date and self.completion_date: if self.project_start_date and self.completion_date:
if getdate(self.completion_date) < getdate(self.project_start_date): if getdate(self.completion_date) < getdate(self.project_start_date):
frappe.throw(_("Expected Completion Date can not be less than Project Start Date")) frappe.throw(_("Expected Completion Date can not be less than Project Start Date"))
def validate_tasks(self):
if not self.tasks:
frappe.throw("Task is mandatory against a project")
def sync_tasks(self): def sync_tasks(self):
"""sync tasks and remove table""" """sync tasks and remove table"""
@ -74,8 +69,6 @@ class Project(Document):
for t in frappe.get_all("Task", ["name"], {"project": self.name, "name": ("not in", task_names)}): for t in frappe.get_all("Task", ["name"], {"project": self.name, "name": ("not in", task_names)}):
frappe.delete_doc("Task", t.name) frappe.delete_doc("Task", t.name)
self.tasks = []
def update_percent_complete(self): def update_percent_complete(self):
total = frappe.db.sql("""select count(*) from tabTask where project=%s""", total = frappe.db.sql("""select count(*) from tabTask where project=%s""",
self.name)[0][0] self.name)[0][0]
@ -85,7 +78,6 @@ class Project(Document):
frappe.db.set_value("Project", self.name, "percent_complete", frappe.db.set_value("Project", self.name, "percent_complete",
int(float(completed) / total * 100)) int(float(completed) / total * 100))
@frappe.whitelist() @frappe.whitelist()
def get_cost_center_name(project_name): def get_cost_center_name(project_name):
return frappe.db.get_value("Project", project_name, "cost_center") return frappe.db.get_value("Project", project_name, "cost_center")

View File

@ -61,14 +61,11 @@ class Task(Document):
self.act_end_date= tl.end_date self.act_end_date= tl.end_date
def update_project(self): def update_project(self):
if self.project: if self.project and frappe.db.exists("Project", self.project):
total_activity_cost = frappe.db.sql("""select sum(actual_cost) from `tabTask` total_cost = frappe.db.sql("""select sum(actual_cost) as actual_cost, sum(total_expense_claim) as expense_claim
where project = %s""",self.project) from `tabTask` where project = %s""", self.project, as_dict=1)[0]
frappe.db.set_value("Project", self.project, "total_activity_cost", total_activity_cost) frappe.db.set_value("Project", self.project, "total_activity_cost", total_cost.actual_cost)
frappe.db.set_value("Project", self.project, "total_expense_claim", total_cost.expense_claim)
total_expense_claim = frappe.db.sql("""select sum(total_expense_claim) from `tabTask`
where project = %s""",self.project)
frappe.db.set_value("Project", self.project, "total_expense_claim", total_expense_claim)
@frappe.whitelist() @frappe.whitelist()
def get_events(start, end, filters=None): def get_events(start, end, filters=None):