Merge pull request #3899 from nabinhait/project

[fix] Purchase cost against project
This commit is contained in:
Anand Doshi 2015-08-19 11:58:12 +05:30
commit 6e82d7b50d
3 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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()

View File

@ -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):