Merge pull request #3192 from neilLasrado/purchase-costing
Purchase costing in Projects
This commit is contained in:
commit
4f41bb35b9
@ -5,21 +5,6 @@
|
|||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"fields": [
|
"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",
|
"fieldname": "naming_series",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
@ -953,7 +938,7 @@
|
|||||||
"icon": "icon-file-text",
|
"icon": "icon-file-text",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"modified": "2015-04-27 20:32:12.436976",
|
"modified": "2015-04-30 03:05:13.790265",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Purchase Invoice",
|
"name": "Purchase Invoice",
|
||||||
|
|||||||
@ -239,6 +239,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.update_against_document_in_jv()
|
self.update_against_document_in_jv()
|
||||||
self.update_prevdoc_status()
|
self.update_prevdoc_status()
|
||||||
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
||||||
|
self.update_project()
|
||||||
|
|
||||||
def make_gl_entries(self):
|
def make_gl_entries(self):
|
||||||
auto_accounting_for_stock = \
|
auto_accounting_for_stock = \
|
||||||
@ -373,9 +374,17 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.update_prevdoc_status()
|
self.update_prevdoc_status()
|
||||||
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
||||||
self.make_gl_entries_on_cancel()
|
self.make_gl_entries_on_cancel()
|
||||||
|
self.update_project()
|
||||||
|
|
||||||
def on_update(self):
|
def update_project(self):
|
||||||
pass
|
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()
|
@frappe.whitelist()
|
||||||
def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
|
def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
|
||||||
|
|||||||
@ -6,7 +6,6 @@ from __future__ import unicode_literals
|
|||||||
import unittest
|
import unittest
|
||||||
import frappe
|
import frappe
|
||||||
import frappe.model
|
import frappe.model
|
||||||
import json
|
|
||||||
from frappe.utils import cint
|
from frappe.utils import cint
|
||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \
|
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \
|
||||||
@ -235,4 +234,46 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
from erpnext.controllers.tests.test_recurring_document import test_recurring_document
|
from erpnext.controllers.tests.test_recurring_document import test_recurring_document
|
||||||
test_recurring_document(self, test_records)
|
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')
|
test_records = frappe.get_test_records('Purchase Invoice')
|
||||||
|
|||||||
@ -303,6 +303,15 @@
|
|||||||
"precision": "",
|
"precision": "",
|
||||||
"read_only": 1
|
"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",
|
"fieldname": "margin",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
@ -347,7 +356,7 @@
|
|||||||
"icon": "icon-puzzle-piece",
|
"icon": "icon-puzzle-piece",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"max_attachments": 4,
|
"max_attachments": 4,
|
||||||
"modified": "2015-04-23 05:51:53.642253",
|
"modified": "2015-04-27 07:37:44.239930",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Projects",
|
"module": "Projects",
|
||||||
"name": "Project",
|
"name": "Project",
|
||||||
|
|||||||
@ -90,6 +90,10 @@ class Project(Document):
|
|||||||
if self.total_billing_amount:
|
if self.total_billing_amount:
|
||||||
self.per_gross_margin = (self.gross_margin / flt(self.total_billing_amount)) *100
|
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()
|
@frappe.whitelist()
|
||||||
def get_cost_center_name(project_name):
|
def get_cost_center_name(project_name):
|
||||||
return frappe.db.get_value("Project", project_name, "cost_center")
|
return frappe.db.get_value("Project", project_name, "cost_center")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user