Merge pull request #3192 from neilLasrado/purchase-costing

Purchase costing in Projects
This commit is contained in:
Rushabh Mehta 2015-05-05 10:59:11 +05:30
commit 4f41bb35b9
5 changed files with 69 additions and 21 deletions

View File

@ -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",
@ -953,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",

View File

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

View File

@ -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,47 @@ 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",
"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"
},
{
"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"
}
]
})
purchase_invoice.save()
purchase_invoice.submit()
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), 2000)
purchase_invoice1 = frappe.copy_doc(purchase_invoice)
purchase_invoice1.save()
purchase_invoice1.submit()
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), 4000)
purchase_invoice1.cancel()
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')

View File

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

View File

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