From 349461e9e6c5507e16f4560f6ddab32196e553ab Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 28 Apr 2015 16:29:58 +0530 Subject: [PATCH] Test Cases Added --- .../purchase_invoice/purchase_invoice.py | 2 ++ .../purchase_invoice/test_purchase_invoice.py | 31 ++++++++++++++++++- erpnext/projects/doctype/project/project.py | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 31213afe70..8c238679b5 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -364,6 +364,8 @@ class PurchaseInvoice(BuyingController): ) if gl_entries: + for d in gl_entries: + print d.account, d.debit, d.credit from erpnext.accounts.general_ledger import make_gl_entries make_gl_entries(gl_entries, cancel=(self.docstatus == 2)) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 5ae47d7c4f..b68220523d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals import unittest import frappe import frappe.model -import json from frappe.utils import cint import frappe.defaults from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \ @@ -234,5 +233,35 @@ class TestPurchaseInvoice(unittest.TestCase): def test_recurring_invoice(self): from erpnext.controllers.tests.test_recurring_document import test_recurring_document test_recurring_document(self, test_records) + + def test_total_purchase_cost_for_project(self): + 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, + "item_code": "_Test Item Home Desktop 100", + "expense_account": "_Test Account Cost for Goods Sold - _TC" + }, + { + "rate": 1500, + "qty": 1, + "item_code": "_Test Item Home Desktop 200", + "expense_account": "_Test Account Cost for Goods Sold - _TC" + } + ] + }) + purchase_invoice.save() + purchase_invoice.submit() + self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), 2000) + + purchase_invoice.cancel() + self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), 0) + test_records = frappe.get_test_records('Purchase Invoice') diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index eba56d521e..839ad1d62d 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -92,7 +92,7 @@ class Project(Document): 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 + from `tabPurchase Invoice` where project = %s and docstatus=1 """, self.name, as_dict=1)[0].cost or 0 @frappe.whitelist() def get_cost_center_name(project_name):