perf: Optimisation of project and task updation
This commit is contained in:
@@ -789,9 +789,8 @@ class PurchaseInvoice(BuyingController):
|
|||||||
for d in self.items:
|
for d in self.items:
|
||||||
if d.project and d.project not in project_list:
|
if d.project and d.project not in project_list:
|
||||||
project = frappe.get_doc("Project", d.project)
|
project = frappe.get_doc("Project", d.project)
|
||||||
project.flags.dont_sync_tasks = True
|
|
||||||
project.update_purchase_costing()
|
project.update_purchase_costing()
|
||||||
project.save()
|
project.db_update()
|
||||||
project_list.append(d.project)
|
project_list.append(d.project)
|
||||||
|
|
||||||
def validate_supplier_invoice(self):
|
def validate_supplier_invoice(self):
|
||||||
|
|||||||
@@ -1022,9 +1022,8 @@ class SalesInvoice(SellingController):
|
|||||||
def update_project(self):
|
def update_project(self):
|
||||||
if self.project:
|
if self.project:
|
||||||
project = frappe.get_doc("Project", self.project)
|
project = frappe.get_doc("Project", self.project)
|
||||||
project.flags.dont_sync_tasks = True
|
|
||||||
project.update_billed_amount()
|
project.update_billed_amount()
|
||||||
project.save()
|
project.db_update()
|
||||||
|
|
||||||
|
|
||||||
def verify_payment_amount_is_positive(self):
|
def verify_payment_amount_is_positive(self):
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ class Project(Document):
|
|||||||
|
|
||||||
self.update_costing()
|
self.update_costing()
|
||||||
|
|
||||||
def __setup__(self):
|
def before_print(self):
|
||||||
self.onload()
|
self.onload()
|
||||||
|
|
||||||
def load_tasks(self):
|
def load_tasks(self):
|
||||||
"""Load `tasks` from the database"""
|
"""Load `tasks` from the database"""
|
||||||
|
project_task_custom_fields = frappe.get_all("Custom Field", {"dt": "Project Task"}, "fieldname")
|
||||||
|
|
||||||
self.tasks = []
|
self.tasks = []
|
||||||
for task in self.get_tasks():
|
for task in self.get_tasks():
|
||||||
task_map = {
|
task_map = {
|
||||||
@@ -47,7 +49,7 @@ class Project(Document):
|
|||||||
"task_weight": task.task_weight
|
"task_weight": task.task_weight
|
||||||
}
|
}
|
||||||
|
|
||||||
self.map_custom_fields(task, task_map)
|
self.map_custom_fields(task, task_map, project_task_custom_fields)
|
||||||
|
|
||||||
self.append("tasks", task_map)
|
self.append("tasks", task_map)
|
||||||
|
|
||||||
@@ -149,7 +151,7 @@ class Project(Document):
|
|||||||
"task_weight": t.task_weight
|
"task_weight": t.task_weight
|
||||||
})
|
})
|
||||||
|
|
||||||
self.map_custom_fields(t, task)
|
self.map_custom_fields(t, task, custom_fields)
|
||||||
|
|
||||||
task.flags.ignore_links = True
|
task.flags.ignore_links = True
|
||||||
task.flags.from_project = True
|
task.flags.from_project = True
|
||||||
@@ -173,10 +175,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)}):
|
||||||
self.deleted_task_list.append(t.name)
|
self.deleted_task_list.append(t.name)
|
||||||
|
|
||||||
def update_costing_and_percentage_complete(self):
|
|
||||||
self.update_percent_complete()
|
|
||||||
self.update_costing()
|
|
||||||
|
|
||||||
def is_row_updated(self, row, existing_task_data, fields):
|
def is_row_updated(self, row, existing_task_data, fields):
|
||||||
if self.get("__islocal") or not existing_task_data: return True
|
if self.get("__islocal") or not existing_task_data: return True
|
||||||
|
|
||||||
@@ -186,10 +184,8 @@ class Project(Document):
|
|||||||
if row.get(field) != d.get(field):
|
if row.get(field) != d.get(field):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def map_custom_fields(self, source, target):
|
def map_custom_fields(self, source, target, custom_fields):
|
||||||
project_task_custom_fields = frappe.get_all("Custom Field", {"dt": "Project Task"}, "fieldname")
|
for field in custom_fields:
|
||||||
|
|
||||||
for field in project_task_custom_fields:
|
|
||||||
target.update({
|
target.update({
|
||||||
field.fieldname: source.get(field.fieldname)
|
field.fieldname: source.get(field.fieldname)
|
||||||
})
|
})
|
||||||
@@ -197,8 +193,6 @@ class Project(Document):
|
|||||||
def update_project(self):
|
def update_project(self):
|
||||||
self.update_percent_complete()
|
self.update_percent_complete()
|
||||||
self.update_costing()
|
self.update_costing()
|
||||||
self.flags.dont_sync_tasks = True
|
|
||||||
self.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if self.sales_order:
|
if self.sales_order:
|
||||||
@@ -233,6 +227,7 @@ class Project(Document):
|
|||||||
self.status = "Completed"
|
self.status = "Completed"
|
||||||
elif not self.status == "Cancelled":
|
elif not self.status == "Cancelled":
|
||||||
self.status = "Open"
|
self.status = "Open"
|
||||||
|
self.db_update()
|
||||||
|
|
||||||
def update_costing(self):
|
def update_costing(self):
|
||||||
from_time_sheet = frappe.db.sql("""select
|
from_time_sheet = frappe.db.sql("""select
|
||||||
@@ -260,6 +255,7 @@ class Project(Document):
|
|||||||
self.update_sales_amount()
|
self.update_sales_amount()
|
||||||
self.update_billed_amount()
|
self.update_billed_amount()
|
||||||
self.calculate_gross_margin()
|
self.calculate_gross_margin()
|
||||||
|
self.db_update()
|
||||||
|
|
||||||
def calculate_gross_margin(self):
|
def calculate_gross_margin(self):
|
||||||
expense_amount = (flt(self.total_costing_amount) + flt(self.total_expense_claim)
|
expense_amount = (flt(self.total_costing_amount) + flt(self.total_expense_claim)
|
||||||
@@ -313,7 +309,7 @@ class Project(Document):
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.delete_task()
|
self.delete_task()
|
||||||
self.load_tasks()
|
self.load_tasks()
|
||||||
self.update_costing_and_percentage_complete()
|
self.update_project()
|
||||||
self.update_dependencies_on_duplicated_project()
|
self.update_dependencies_on_duplicated_project()
|
||||||
|
|
||||||
def delete_task(self):
|
def delete_task(self):
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Task(NestedSet):
|
|||||||
|
|
||||||
def update_project(self):
|
def update_project(self):
|
||||||
if self.project and not self.flags.from_project:
|
if self.project and not self.flags.from_project:
|
||||||
frappe.get_doc("Project", self.project).update_project()
|
frappe.get_doc("Project", self.project).update_percent_complete()
|
||||||
|
|
||||||
def check_recursion(self):
|
def check_recursion(self):
|
||||||
if self.flags.ignore_recursion_check: return
|
if self.flags.ignore_recursion_check: return
|
||||||
|
|||||||
@@ -202,9 +202,8 @@ class SalesOrder(SellingController):
|
|||||||
|
|
||||||
if self.project:
|
if self.project:
|
||||||
project = frappe.get_doc("Project", self.project)
|
project = frappe.get_doc("Project", self.project)
|
||||||
project.flags.dont_sync_tasks = True
|
|
||||||
project.update_sales_amount()
|
project.update_sales_amount()
|
||||||
project.save()
|
project.db_update()
|
||||||
|
|
||||||
def check_credit_limit(self):
|
def check_credit_limit(self):
|
||||||
# if bypass credit limit check is set to true (1) at sales order level,
|
# if bypass credit limit check is set to true (1) at sales order level,
|
||||||
|
|||||||
Reference in New Issue
Block a user