New Purchase Order generates TypeError But Not Adding to Existing Purchase Order

Hello,

Hoping someone can shine a light or point me in the right direction to find an answer to this.

If I try to generate a new Purchase Order (renamed Purchase Request in my setup) and add an item to it, I get the TypeError message (details are further down the post).

TypeError: cannot unpack non-iterable NoneType object

However if i edit an existing draft Purchase Order, using the same Demo company and same item, the item is added without an error.

Can anyone suggest what the source of the error is?

App Versions

{
	"erpnext": "15.39.3",
	"frappe": "15.45.1",
	"print_designer": "1.0.0-dev"
}

Route

Form/Purchase Order/new-purchase-order-nioqhrxeqi

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 114, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1778, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/get_item_details.py", line 107, in get_item_details
    update_bin_details(args, out, doc)
  File "apps/erpnext/erpnext/stock/get_item_details.py", line 166, in update_bin_details
    bin_details = get_bin_details(args.item_code, out.warehouse, company, include_child_warehouses=True)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/get_item_details.py", line 1181, in get_bin_details
    warehouses = get_child_warehouses(warehouse) if include_child_warehouses else [warehouse]
  File "apps/erpnext/erpnext/stock/doctype/warehouse/warehouse.py", line 218, in get_child_warehouses
    children = get_descendants_of("Warehouse", warehouse, ignore_permissions=True, order_by="lft")
  File "apps/frappe/frappe/utils/nestedset.py", line 393, in get_descendants_of
    lft, rgt = frappe.db.get_value(doctype, name, ["lft", "rgt"])
TypeError: cannot unpack non-iterable NoneType object

Request Data

{
	"type": "POST",
	"args": {
		"doc": "{\"docstatus\":0,\"doctype\":\"Purchase Order\",\"name\":\"new-purchase-order-mlrveynllp\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"title\":\"{supplier_name}\",\"schedule_date\":\"2024-10-29\",\"apply_tds\":0,\"is_subcontracted\":0,\"naming_series\":\"PUR-.YY.MM.DD.-.##\",\"transaction_date\":\"2024-10-29\",\"company\":\"GlucoRx Technologies Limited (Demo)\",\"currency\":\"GBP\",\"buying_price_list\":\"Standard Buying\",\"price_list_currency\":\"GBP\",\"ignore_pricing_rule\":0,\"set_warehouse\":\"Stores\",\"items\":[{\"docstatus\":0,\"doctype\":\"Purchase Order Item\",\"name\":\"new-purchase-order-item-frxylnltdr\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"fg_item_qty\":1,\"stock_uom\":\"Nos\",\"margin_type\":\"\",\"is_free_item\":0,\"apply_tds\":1,\"delivered_by_supplier\":0,\"against_blanket_order\":0,\"include_exploded_items\":0,\"is_fixed_asset\":0,\"page_break\":0,\"parent\":\"new-purchase-order-mlrveynllp\",\"parentfield\":\"items\",\"parenttype\":\"Purchase Order\",\"idx\":1,\"schedule_date\":\"2024-10-29\",\"warehouse\":\"Stores\",\"qty\":0,\"conversion_factor\":0,\"stock_qty\":0,\"price_list_rate\":0,\"last_purchase_rate\":0,\"base_price_list_rate\":0,\"margin_rate_or_amount\":0,\"rate_with_margin\":0,\"discount_amount\":0,\"base_rate_with_margin\":0,\"rate\":0,\"amount\":0,\"base_rate\":0,\"base_amount\":0,\"stock_uom_rate\":0,\"net_rate\":0,\"net_amount\":0,\"base_net_rate\":0,\"base_net_amount\":0,\"actual_qty\":0,\"company_total_stock\":0,\"blanket_order_rate\":0,\"received_qty\":0,\"returned_qty\":0,\"billed_amt\":0,\"weight_per_unit\":0,\"total_weight\":0,\"item_code\":\"snbn\",\"weight_uom\":\"\",\"barcode\":null,\"pricing_rules\":\"\"}],\"tax_withholding_net_total\":0,\"pricing_rules\":[],\"supplied_items\":[],\"taxes\":[],\"disable_rounded_total\":0,\"apply_discount_on\":\"Grand Total\",\"payment_schedule\":[],\"status\":\"Draft\",\"per_billed\":\"100\",\"group_same_items\":0,\"is_internal_supplier\":0,\"party_account_currency\":\"GBP\",\"is_old_subcontracting_flow\":0,\"advance_paid\":0,\"conversion_rate\":1,\"plc_conversion_rate\":1,\"base_net_total\":0,\"net_total\":0,\"base_total\":0,\"total\":0,\"total_qty\":0,\"rounding_adjustment\":0,\"grand_total\":0,\"taxes_and_charges_deducted\":0,\"taxes_and_charges_added\":0,\"base_grand_total\":0,\"base_taxes_and_charges_added\":0,\"base_taxes_and_charges_deducted\":0,\"total_taxes_and_charges\":0,\"base_total_taxes_and_charges\":0,\"base_rounding_adjustment\":0,\"rounded_total\":0,\"base_rounded_total\":0,\"in_words\":\"\",\"base_in_words\":\"\",\"base_discount_amount\":0,\"supplier_name\":\"Summit Traders Ltd.\",\"represents_company\":\"\",\"supplier\":\"Summit Traders Ltd.\",\"supplier_address\":null,\"address_display\":null,\"tax_category\":\"\",\"contact_person\":null,\"contact_display\":null,\"contact_email\":null,\"contact_mobile\":null,\"language\":\"en-GB\",\"payment_terms_template\":null}",
		"args": "{\"item_code\":\"snbn\",\"barcode\":null,\"set_warehouse\":\"Stores\",\"warehouse\":\"Stores\",\"supplier\":\"Summit Traders Ltd.\",\"currency\":\"GBP\",\"is_internal_supplier\":0,\"update_stock\":0,\"conversion_rate\":1,\"price_list\":\"Standard Buying\",\"price_list_currency\":\"GBP\",\"plc_conversion_rate\":1,\"company\":\"GlucoRx Technologies Limited (Demo)\",\"is_pos\":0,\"is_return\":0,\"is_subcontracted\":0,\"ignore_pricing_rule\":0,\"doctype\":\"Purchase Order\",\"name\":\"new-purchase-order-mlrveynllp\",\"qty\":1,\"net_rate\":0,\"base_net_rate\":0,\"stock_qty\":0,\"conversion_factor\":0,\"weight_per_unit\":0,\"weight_uom\":\"\",\"stock_uom\":\"Nos\",\"pos_profile\":\"\",\"tax_category\":\"\",\"child_doctype\":\"Purchase Order Item\",\"child_docname\":\"new-purchase-order-item-frxylnltdr\",\"is_old_subcontracting_flow\":0}"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/erpnext.stock.get_item_details.get_item_details",
	"request_id": null
}

Response Data

{
	"exception": "TypeError: cannot unpack non-iterable NoneType object",
	"exc_type": "TypeError",
	"_exc_source": "erpnext (app)"
}

So I can add an Item to a new Purchase Receipt or new Stock Entry but a new Purchase Order still generates this error.

Editing an existing Purchase Order allows a new Item to be added and not generate this error.

Is there a problem with the Purchase Order DocType. It has been a customised a little, would resetting these customisations help?

Didn’t manage to resolve this, ended up reinstalling and restoring a backup that was not affected by this issue.

Warehouses were not customised, as one person had suggested to look at, but the Item Groups were. Will see is the issue reappears when I customise my setup again.