diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 03ed987745d..0f1eb4bf28a 100755 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -5,21 +5,6 @@ "docstatus": 0, "doctype": "DocType", "fields": [ - { - "fieldname": "supplier_section", - "fieldtype": "Section Break", - "label": "", - "options": "icon-user", - "permlevel": 0 - }, - { - "fieldname": "column_break0", - "fieldtype": "Column Break", - "oldfieldtype": "Column Break", - "permlevel": 0, - "read_only": 0, - "width": "50%" - }, { "fieldname": "naming_series", "fieldtype": "Select", @@ -91,6 +76,14 @@ "print_hide": 1, "read_only": 1 }, + { + "fieldname": "project", + "fieldtype": "Link", + "label": "Project", + "options": "Project", + "permlevel": 0, + "precision": "" + }, { "fieldname": "column_break1", "fieldtype": "Column Break", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 094d30cff3c..31213afe70c 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -239,6 +239,7 @@ class PurchaseInvoice(BuyingController): self.update_against_document_in_jv() self.update_prevdoc_status() self.update_billing_status_for_zero_amount_refdoc("Purchase Order") + self.update_project() def make_gl_entries(self): auto_accounting_for_stock = \ @@ -373,9 +374,14 @@ class PurchaseInvoice(BuyingController): self.update_prevdoc_status() self.update_billing_status_for_zero_amount_refdoc("Purchase Order") self.make_gl_entries_on_cancel() - - def on_update(self): - pass + self.update_project() + + def update_project(self): + if self.project and frappe.db.exists("Project", self.project): + project = frappe.get_doc("Project", self.project) + project.flags.dont_sync_tasks = True + project.update_purchase_costing() + project.save() @frappe.whitelist() def get_expense_account(doctype, txt, searchfield, start, page_len, filters): diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json index 4db087bb446..2aca991877e 100644 --- a/erpnext/projects/doctype/project/project.json +++ b/erpnext/projects/doctype/project/project.json @@ -303,6 +303,15 @@ "precision": "", "read_only": 1 }, + { + "fieldname": "total_purchase_cost", + "fieldtype": "Currency", + "hidden": 0, + "label": "Total Purchase Cost (via Purchase Invoice)", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, { "fieldname": "margin", "fieldtype": "Section Break", @@ -347,7 +356,7 @@ "icon": "icon-puzzle-piece", "idx": 1, "max_attachments": 4, - "modified": "2015-04-23 05:51:53.642253", + "modified": "2015-04-27 07:37:44.239930", "modified_by": "Administrator", "module": "Projects", "name": "Project", diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 89cf523c1e4..eba56d521e3 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -89,6 +89,10 @@ class Project(Document): self.gross_margin = flt(total_cost.billing_amount) - flt(total_cost.costing_amount) if self.total_billing_amount: 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(grand_total) as cost + from `tabPurchase Invoice` where project = %s and docstatus=1 """, self.name, as_dict=1)[0].cost @frappe.whitelist() def get_cost_center_name(project_name):