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
This commit is contained in:
Andy Villiger 2018-01-26 06:41:19 +01:00 committed by Nabin Hait
parent db4fd7f5b6
commit 567623654b

View File

@ -567,10 +567,12 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
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": {