Resolve issue #10914 - Error when making Sales Invoice (#12656)
* Resolve issue #10914
An exception was raised when a Sales Order has been created to a Sales Invoice and one of the items had no Item Code.
* Update sales_order.py
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 1c3354c..5bacf28 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -567,10 +567,12 @@
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", source_parent.project, "cost_center") \
- or item.selling_cost_center \
- or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
+ if source_parent.project:
+ target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center")
+ if not target.cost_center and target.item_code:
+ item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
+ target.cost_center = 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": {