ERROR: Unable to fetch item code

Hello,

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)

@yoyowu1000

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
net_weight=item_doc.custom_net_weight_corton_kg
no_of_ctn = item.no_of_ctn
# item.total_kg = net_weightno_of_ctn
frappe.msgprint(str(net_weight
no_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 %}
        <tr>
            <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 }}
                    </div>
                </div>
            </td>
            <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>
        </tr>
    {% endfor %}

1 Like

Hello @yoyowu1000 Thanks

1 Like

facing the same issue my client script is it not working, I am uploading .csv file in material request item table by filling item_name but it is not fetching its corresponding item_code and I dont know when to trigger that client script! Help