Okay I have made it work by copying the parameters called from front end.
So I've got to specify metadata_loaded param as: ["Purchase Receipt","Purchase Receipt Item","Purchase Taxes and Charges","Purchase Receipt Item Supplied","Page","Page Role","Purchase Order","Purchase Order Item","Purchase Order Item Supplied","Purchase Invoice","Purchase Invoice Item","Purchase Invoice Advance"]
Initially i thought just "Purchase Receipt" and related doctype are enough but turned out, it requires the whole array. Can someone explain a bit what is this metadata_loaded for ?
This applies also to the normal api call: /api/method/frappe.widgets.form.utils.get_linked_docs?doctype=Purchase Order&name=PO9999
Meaning if you don't specify same parameter for this api call, it will not return correct information.
Instead it dumps all the fields available in Purchase Receipt, something like:
{
"docs": [
{
"fields": [
{
"creation": "2013-05-21 16:16:39",
"search_fields": null,
"doctype": "DocField",
"owner": "Administrator",
"modified_by": "Administrator",
"label": "Supplier",
"docstatus": 0,
"permlevel": 0,
"link_doctype": null,
"parent": "Purchase Invoice",
"name": "FL07961",
"idx": 1,
"modified": "2014-07-04 11:25:34.977669",
"parenttype": "DocType",
"fieldname": "supplier_section",
"fieldtype": "Section Break",
"options": "icon-user",
"parentfield": "fields"
},
{
"oldfieldtype": "Column Break",
"creation": "2013-05-21 16:16:39",
"search_fields": null,
"doctype": "DocField",
"owner": "Administrator",
"read_only": 0,
"modified_by": "Administrator",
"width": "50%",
"docstatus": 0,
"permlevel": 0,
"link_doctype": null,
"parent": "Purchase Invoice",
"name": "FL07962",
"idx": 2,
"modified": "2014-07-04 11:25:34.977669",
"parenttype": "DocType",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"parentfield": "fields"
}
............
Should I report this as a bug ? Seem to be these 2 lines in get_linked_docs:
if not dt in metadata_loaded:
frappe.local.response.docs.extend(link_meta_bundle)
Thank you!