From f288866130d44403a43e81627e8ca96b75e29d91 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 20 Mar 2019 13:34:28 +0530 Subject: [PATCH] fix: Cost center from PO to PI is not mapping --- .../doctype/purchase_invoice/purchase_invoice.js | 9 +++++++++ erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 9 +++++++++ erpnext/buying/doctype/purchase_order/purchase_order.py | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index b4fd91f6e4..c94c85cb95 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -510,6 +510,15 @@ frappe.ui.form.on("Purchase Invoice", { } } } + + frm.set_query("cost_center", function() { + return { + filters: { + company: frm.doc.company, + is_group: 0 + } + }; + }); }, onload: function(frm) { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 3816632065..0399cf9583 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -564,6 +564,15 @@ frappe.ui.form.on('Sales Invoice', { }; }); + frm.set_query("cost_center", function() { + return { + filters: { + company: frm.doc.company, + is_group: 0 + } + }; + }); + frm.custom_make_buttons = { 'Delivery Note': 'Delivery', 'Sales Invoice': 'Sales Return', diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index a4a636d6ba..720160676f 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -388,9 +388,10 @@ def make_purchase_invoice(source_name, target_doc=None): item = get_item_defaults(target.item_code, source_parent.company) item_group = get_item_group_defaults(target.item_code, source_parent.company) - target.cost_center = frappe.db.get_value("Project", obj.project, "cost_center") \ - or item.get("buying_cost_center") \ - or item_group.get("buying_cost_center") + target.cost_center = (obj.cost_center + or frappe.db.get_value("Project", obj.project, "cost_center") + or item.get("buying_cost_center") + or item_group.get("buying_cost_center")) doc = get_mapped_doc("Purchase Order", source_name, { "Purchase Order": {