From fa5fcf5405e14dbce141475c3d8a151a3eb1ba0a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 18 Aug 2015 12:39:50 +0530 Subject: [PATCH] [fix] Purchase cost against project --- erpnext/patches.txt | 1 + .../v5_4/update_purchase_cost_against_project.py | 11 +++++++++++ erpnext/projects/doctype/project/project.py | 6 ++++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v5_4/update_purchase_cost_against_project.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 87a555111b..551518e6e8 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -192,3 +192,4 @@ erpnext.patches.v5_4.cleanup_journal_entry #2015-08-14 execute:frappe.db.sql("update `tabProduction Order` pro set description = (select description from tabItem where name=pro.production_item) where ifnull(description, '') = ''") erpnext.patches.v5_7.item_template_attributes erpnext.patches.v4_2.repost_reserved_qty #2015-08-17 +erpnext.patches.v5_4.update_purchase_cost_against_project diff --git a/erpnext/patches/v5_4/update_purchase_cost_against_project.py b/erpnext/patches/v5_4/update_purchase_cost_against_project.py new file mode 100644 index 0000000000..7e54738d4d --- /dev/null +++ b/erpnext/patches/v5_4/update_purchase_cost_against_project.py @@ -0,0 +1,11 @@ +# Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for p in frappe.get_all("Project"): + project = frappe.get_doc("Project", p.name) + project.update_purchase_costing() + project.save() \ No newline at end of file diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 6ebafdba59..130627825e 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -107,8 +107,10 @@ class Project(Document): self.per_gross_margin = (self.gross_margin / flt(self.total_billing_amount)) *100 def update_purchase_costing(self): - self.total_purchase_cost = frappe.db.sql("""select sum(amount) as cost - from `tabPurchase Invoice Item` where project_name = %s and docstatus=1 """, self.name, as_dict=1)[0].cost or 0 + total_purchase_cost = frappe.db.sql("""select sum(base_net_amount) + from `tabPurchase Invoice Item` where project_name = %s and docstatus=1 """, self.name) + + self.total_purchase_cost = total_purchase_cost[0][0] if total_purchase_cost else 0 @frappe.whitelist() def get_cost_center_name(project_name):