diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json index dbdffdf1cd..e809328df9 100644 --- a/erpnext/projects/doctype/project/project.json +++ b/erpnext/projects/doctype/project/project.json @@ -1024,6 +1024,35 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "total_sales_cost", + "fieldtype": "Currency", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Total Sales Cost (via Sales Order)", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -1232,4 +1261,4 @@ "timeline_field": "customer", "track_changes": 0, "track_seen": 1 -} \ No newline at end of file +} diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index b5ef4bfd76..289b7dd185 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -176,6 +176,13 @@ class Project(Document): from `tabPurchase Invoice Item` where project = %s and docstatus=1""", self.name) self.total_purchase_cost = total_purchase_cost and total_purchase_cost[0][0] or 0 + + def update_sales_costing(self): + total_sales_cost = frappe.db.sql("""select sum(grand_total) + from `tabSales Order` where project = %s and docstatus=1""", self.name) + + self.total_sales_cost = total_sales_cost and total_sales_cost[0][0] or 0 + def send_welcome_email(self): url = get_url("/project/?name={0}".format(self.name)) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index fdaadd87e0..7c5fb04bf2 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -157,7 +157,7 @@ class SalesOrder(SellingController): self.update_reserved_qty() frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, self.company, self.base_grand_total, self) - + self.update_project() self.update_prevdoc_status('submit') def on_cancel(self): @@ -167,10 +167,19 @@ class SalesOrder(SellingController): self.check_nextdoc_docstatus() self.update_reserved_qty() - + self.update_project() self.update_prevdoc_status('cancel') frappe.db.set(self, 'status', 'Cancelled') + + def update_project(self): + project_list = [] + if self.project: + project = frappe.get_doc("Project", self.project) + project.flags.dont_sync_tasks = True + project.update_sales_costing() + project.save() + project_list.append(self.project) def check_credit_limit(self): from erpnext.selling.doctype.customer.customer import check_credit_limit