From 42a554e5cbbabbc29d59da613502439ce9c51835 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 30 Apr 2015 13:05:36 +0530 Subject: [PATCH] fixes in Purchase Invoice --- .../doctype/purchase_invoice/purchase_invoice.json | 10 +--------- .../doctype/purchase_invoice/purchase_invoice.py | 13 ++++++++----- .../purchase_invoice/test_purchase_invoice.py | 3 ++- erpnext/projects/doctype/project/project.py | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 0f1eb4bf28..edbefba998 100755 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -76,14 +76,6 @@ "print_hide": 1, "read_only": 1 }, - { - "fieldname": "project", - "fieldtype": "Link", - "label": "Project", - "options": "Project", - "permlevel": 0, - "precision": "" - }, { "fieldname": "column_break1", "fieldtype": "Column Break", @@ -946,7 +938,7 @@ "icon": "icon-file-text", "idx": 1, "is_submittable": 1, - "modified": "2015-04-27 20:32:12.436976", + "modified": "2015-04-30 03:05:13.790265", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 31213afe70..c0ebf686cb 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -377,11 +377,14 @@ class PurchaseInvoice(BuyingController): 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() + project_list = [] + for d in self.items: + if d.project_name and d.project_name not in project_list: + project = frappe.get_doc("Project", d.project_name) + project.flags.dont_sync_tasks = True + project.update_purchase_costing() + project.save() + project_list.append(d.project_name) @frappe.whitelist() def get_expense_account(doctype, txt, searchfield, start, page_len, filters): diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index d0fb3d93f3..7f46b083d8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -238,13 +238,13 @@ class TestPurchaseInvoice(unittest.TestCase): purchase_invoice = frappe.new_doc('Purchase Invoice') purchase_invoice.update({ "credit_to": "_Test Payable - _TC", - "project": "_Test Project", "supplier": "_Test Supplier", "company": "_Test Company", "items": [ { "rate": 500, "qty": 1, + "project_name": "_Test Project", "item_code": "_Test Item Home Desktop 100", "expense_account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC" @@ -252,6 +252,7 @@ class TestPurchaseInvoice(unittest.TestCase): { "rate": 1500, "qty": 1, + "project_name": "_Test Project", "item_code": "_Test Item Home Desktop 200", "expense_account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC" diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 839ad1d62d..590788d34d 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -91,8 +91,8 @@ 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(grand_total) as cost - from `tabPurchase Invoice` where project = %s and docstatus=1 """, self.name, as_dict=1)[0].cost or 0 + 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 @frappe.whitelist() def get_cost_center_name(project_name):