Error in Function

Hi,
while using a custom function I am getting error.

JS Code:


frappe.ui.form.on("Sales Order", "before_submit", function(frm, doctype, name){
           var par =  {
                    "source_name": cur_frm
                     };
frappe.call({
                method: "library_management.item_script.generate_custom_codes",
                args: par,
                callback: function(r) { }
           
     });
});

Python Code:

@frappe.whitelist(allow_guest=True)
def generate_custom_codes(source_name):
    doc_m = frappe.get_doc("Item", source_name)
    i='010%'
    j=frappe.db.sql("""select item_code from tabItem where item_code like %s order by item_code desc limit 1""",i)
    prefix=j[0][0]
    prefix="".join(prefix)
    new_prefix=prefix[0:3]
    new_suffix=prefix[4:10]
    next_num=(int(new_suffix)+1)
    next_num1=str(next_num)
    new_num1=next_num1.decode("ascii").rjust(6,'0')
    new_num1=new_prefix+'-'+new_num1
    new_item=frappe.new_doc("Item")
    new_item.item_code =new_num1
    new_item.item_group = doc_m.item_group
    new_item.item_name = "This is the clone of "+doc_m.item_name
    new_item.brand = doc_m.brand
    new_item.description = doc_m.description
    new_item.is_stock_item = doc_m.is_stock_item
    new_item.is_purchase_item=doc_m.is_purchase_item
    new_item.min_order_qty=doc_m.min_order_qty
    new_item.lead_time_days=doc_m.lead_time_days
    new_item.buying_cost_center=doc_m.buying_cost_center
    new_item.expense_account=doc_m.expense_account
    new_item.default_supplier=doc_m.default_supplier
    new_item.last_purchsae_rate=doc_m.last_purchase_rate
    new_item.manufacturer=doc_m.manufacturer
    new_item.manufacturer_part_no=doc_m.manufacturer_part_no
    new_item.is_sales_item=doc_m.is_sales_item
    new_item.inspection_required=doc_m.inspection_required
    new_item.is_sub_contracted_item=doc_m.is_sub_contracted_item
    new_item.show_in_website=doc_m.show_in_website
    new_item.page_name=doc_m.page_name
    new_item.default_warehouse = doc_m.default_warehouse
    new_item.end_of_life =doc_m.end_of_life
    new_item.stock_uom =doc_m.stock_uom
    new_item.tolerance = doc_m.tolerance
    new_item.has_batch_no = doc_m.has_batch_no
    new_item.has_serial_no = doc_m.has_serial_no
    new_item.valuation_method = doc_m.valuation_method
    new_item.warranty_period = doc_m.warranty_period
    new_item.net_weight = doc_m.net_weight
    new_item.weight_uom = doc_m.weight_uom
    new_item.is_asset_item = doc_m.is_asset_item
    new_item.default_bom=doc_m.default_bom
    new_item.insert();
    doc_m.save();
    doc_m.run_method("on_update");

Error:
TypeError: b is undefined

Does anyone has an idea about this?

Regards
Ruchin Sharma

can you share the traceback / chrome’s console log ?

@makarand_b

Here is the traceback:
Media resource http://localhost/assets/frappe/sounds/delete.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
Media resource http://localhost/assets/frappe/sounds/cancel.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
Media resource http://localhost/assets/frappe/sounds/error.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
Media resource http://localhost/assets/frappe/sounds/email.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
Media resource http://localhost/assets/frappe/sounds/click.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
Media resource http://localhost/assets/frappe/sounds/submit.mp3 could not be decoded. desk
All candidate resources failed to load. Media load paused. desk
TypeError: b is undefined jquery.min.js:3:5565
Use of getPreventDefault() is deprecated. Use defaultPrevented instead. desk
POST
XHR
http://localhost/ [HTTP/1.1 200 OK 258ms]
POST
XHR
http://localhost/ [HTTP/1.1 200 OK 336ms]
POST
XHR
http://localhost/ [HTTP/1.1 200 OK 259ms]

check the issue at line number 5565, you might be able to get the route cause of the issue.

Hi @makarand_b
My code doesn’t have this much of lines.

Regards
Ruchin Sharma