Skip to content

Commit

Permalink
fix: update the project after task deletion so that the % completed s… (
Browse files Browse the repository at this point in the history
#22591)

* fix: update the project after task deletion so that the % completed shows correct value

* fix: patch to correct % complete of previous projects

* fix: for version-13

* fix: removed patch from v13

Co-authored-by: Marica <maricadsouza221197@gmail.com>
Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com>
Co-authored-by: Nabin Hait <nabinhait@gmail.com>
  • Loading branch information
4 people authored Jul 24, 2020
1 parent 91fe106 commit ecb1460
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ erpnext.patches.v13_0.move_payroll_setting_separately_from_hr_settings #22-06-20
erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020
erpnext.patches.v13_0.loyalty_points_entry_for_pos_invoice #22-07-2020
erpnext.patches.v12_0.add_taxjar_integration_field
erpnext.patches.v12_0.fix_percent_complete_for_projects
erpnext.patches.v13_0.delete_report_requested_items_to_order
erpnext.patches.v12_0.update_item_tax_template_company
erpnext.patches.v13_0.move_branch_code_to_bank_account
Expand Down
14 changes: 14 additions & 0 deletions erpnext/patches/v12_0/fix_percent_complete_for_projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import frappe
from frappe.utils import flt

def execute():
for project in frappe.get_all("Project", fields=["name", "percent_complete_method"]):
total = frappe.db.count('Task', dict(project=project.name))
if project.percent_complete_method == "Task Completion" and total > 0:
completed = frappe.db.sql("""select count(name) from tabTask where
project=%s and status in ('Cancelled', 'Completed')""", project.name)[0][0]
percent_complete = flt(flt(completed) / total * 100, 2)
if project.percent_complete != percent_complete:
frappe.db.set_value("Project", project.name, "percent_complete", percent_complete)
if percent_complete == 100:
frappe.db.set_value("Project", project.name, "status", "Completed")
3 changes: 3 additions & 0 deletions erpnext/projects/doctype/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def on_trash(self):

self.update_nsm_model()

def after_delete(self):
self.update_project()

def update_status(self):
if self.status not in ('Cancelled', 'Completed') and self.exp_end_date:
from datetime import datetime
Expand Down

0 comments on commit ecb1460

Please sign in to comment.