From 55a879791956e0709d0d29639edc1e32403f624d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 18 Oct 2016 14:54:17 +0530 Subject: [PATCH] Set cost center while creating invoice from SO/PO --- erpnext/accounts/doctype/cost_center/cost_center.json | 9 +++++---- erpnext/buying/doctype/purchase_order/purchase_order.py | 5 +++++ erpnext/selling/doctype/sales_order/sales_order.py | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json index 5f78a5ba8a..ba32439792 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.json +++ b/erpnext/accounts/doctype/cost_center/cost_center.json @@ -10,6 +10,7 @@ "docstatus": 0, "doctype": "DocType", "document_type": "Setup", + "editable_grid": 0, "fields": [ { "allow_on_submit": 0, @@ -249,14 +250,15 @@ "hide_toolbar": 0, "icon": "icon-money", "idx": 1, - "in_create": 0, + "image_view": 0, + "in_create": 1, "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2016-05-16 15:23:14.770933", + "modified": "2016-10-18 14:22:00.207907", "modified_by": "Administrator", "module": "Accounts", "name": "Cost Center", @@ -368,6 +370,5 @@ "read_only_onload": 0, "search_fields": "parent_cost_center, is_group", "sort_order": "ASC", - "track_seen": 0, - "version": 0 + "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 79b22ae677..3230cd0f4a 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -302,6 +302,11 @@ def make_purchase_invoice(source_name, target_doc=None): target.amount = flt(obj.amount) - flt(obj.billed_amt) target.base_amount = target.amount * flt(source_parent.conversion_rate) target.qty = target.amount / flt(obj.rate) if (flt(obj.rate) and flt(obj.billed_amt)) else flt(obj.qty) + + item = frappe.db.get_value("Item", target.item_code, ["item_group", "buying_cost_center"], as_dict=1) + target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \ + or item.buying_cost_center \ + or frappe.db.get_value("Item Group", item.item_group, "default_cost_center") doc = get_mapped_doc("Purchase Order", source_name, { "Purchase Order": { diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 0435141d53..7ff1471ad8 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -442,6 +442,11 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False): target.amount = flt(source.amount) - flt(source.billed_amt) target.base_amount = target.amount * flt(source_parent.conversion_rate) target.qty = target.amount / flt(source.rate) if (source.rate and source.billed_amt) else source.qty + + item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1) + target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \ + or item.selling_cost_center \ + or frappe.db.get_value("Item Group", item.item_group, "default_cost_center") doclist = get_mapped_doc("Sales Order", source_name, { "Sales Order": {