ERROR: Unable to fetch item code


Why i am getting this iteratively when i am upload items from csv in opportunity?

I have written one client script to get item code from item_name it might be due to that but why iteratively?

Is it possible to share your client script?

It’s difficult to tell without the actually script

But I would assume, it could be that

  1. there doesn’t exist item_code for those items (in the actual Item masters)
  2. there is no item_code from where you are pulling the item_names from (e.g. within the Opportunity document)


for item in doc.items:
item_doc = frappe.get_doc(‘Item’, {‘item_name’: item.item_name})
if not item.item_code:
item.item_code = item_doc.item_code
no_of_ctn = item.no_of_ctn
# item.total_kg = net_weightno_of_ctn

Totally bored of this issue… not getting why its happening…

Try query by the item_code

for example

item_doc = frappe.get_doc(‘Item’, item.item_code)

I’m not sure exactly, but sometimes the item_codes in item_tables (like the ones in opportunity) don’t populate the item_name correctly.

Lastly, this is some jinja code that I use and it has been working fine.

    {% set currency_symbol = frappe.get_doc("Currency", doc.currency).symbol %}
    {% for item in doc.items %}
            <td style="">{{ item.idx }}</td>
            <td style="">{{ item.item_code }}</td>
            <td style="">
                <div class="value">
                    <div class="ql-snow">
                        {{ frappe.get_doc("Item", item.item_code).item_name }}
            <td style="" class="text-right">{{ item.qty }}</td>
            <td style="" class="text-right">{{ currency_symbol }} {{ frappe.utils.fmt_money(item.rate) }}</td>
            <td style="" class="text-right">{{ item.uom }}</td>
            <td style="" class="text-right">{{ currency_symbol }} {{ frappe.utils.fmt_money(item.amount) }}</td>
    {% endfor %}

Hello @yoyowu1000 Thanks

1 Like