Stock balance key error for one item

Hello there,

we have this error only for this item, when calling the stock balance.

Traceback (most recent call last):
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/", line 55, in application
    response = frappe.handler.handle()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/", line 19, in handle
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/", line 36, in execute_cmd
    ret =, **frappe.form_dict)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/", line 879, in call
    return fn(*args, **newargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/desk/", line 88, in run
    res = frappe.get_attr(method_name)(frappe._dict(filters))
  File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/stock/report/stock_balance/", line 21, in execute
    data.append([item, item_map[item]["item_name"],
KeyError: u'ITEM-07961'

I can’t found any difference from this item to others.

Any clues?

EDIT: I realized, that this error occurs, when there are different ITEMs with the same “display name”.

Lets say I have ITEM-07960 and ITEM-07961, both are called “Apple MacBook”. I assume this is a problem for ERPNext, but It shouldn’t be, since the real key should always be the ITEM-Number.

What can I do about this?

Thank you.

@nabinhait @rohit_w can you check?

Hi @ci2016,

I am not able to reproduce this issue, can you provide some more information like filters details, stock availability in the selected period etc.

Thanks, Rohit

Hi @rohit_w,

sorry for the delay.

We have in Stock Settings /desk#Form/Stock Settings/ “Item Naming by” “Naming Series”.

I think this leads to the problem, when the Item has the same name. Is this possible?

I think it is related to wrong case (UPPER/lower) in Item code.
Can you please rename the item to a temporary name and then rename it to original again?

1 Like

@nabinhait After renaming it, to a temporary name, it worked immediately. After that, I only had to rename it to the ITEM-ID again. It still works.

I should have tried this earlier.

Thank you very much!

Edit: I’m not sure about the problem was caused by Upper or lowercase. It was ITEM-07961 before, and it still is.

Hi @nabinhait

Trust you’re doing well. Could you please give some further insight into the cause of this issue? I’m asking because it has implications beyond the Stock Balance report. It also affects function of the POS! The item does not show up in POS when you search by Item Code and if you search by name, it comes up but cannot be selected and also shows wrong Stock Qty

Renaming the item solves all the aforementioned issues so the question is… why does this happen in the first place? For the particular item where we experienced this issue, the item name is written in UPPER case. I’m not sure if this had anything to do with it but we need to get to the bottom of this to avoid future issues please



I am facing the same issue , and by renaming it, it works. Did u upload the items via import?

Hi @vivek

I think so though I’m not 100% sure


Hi @vivek

As I had the same problem, I can say for 100% sure, that I did not import them.

Please help me solving this.

Just a request suggestion to paste your traceback as text - that make it easier you and others to search the code, and also too the code then shows up in forum searches to direct others for clues…