Skip to content

Instantly share code, notes, and snippets.

@nathando
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathando/a37ba1d64945e1b07c99 to your computer and use it in GitHub Desktop.
Save nathando/a37ba1d64945e1b07c99 to your computer and use it in GitHub Desktop.
Custome API
from frappe.widgets.form.utils import get_linked_docs
@frappe.whitelist(allow_guest=False)
def received_po_item():
po_name = frappe.local.form_dict.get('po_name')
pr_name = frappe.local.form_dict.get('pr_name')
item_code = frappe.local.form_dict.get('item_code')
qty = float(frappe.local.form_dict.get('qty', 0))
if po_name:
try:
po_doc = frappe.get_doc("Purchase Order", po_name)
if po_doc.get('docstatus', 0) == 1:
if po_doc.get('per_received', 0) < 1
# Here I wanna query all Purchase Receipt linked with this PO po_doc
# So i try calling get_linked_docs
#### Old code
#### linked_docs = get_linked_docs("Purchase Order", po_name)
# Here after execute this, it directly dump a lot of unneccesary data to the API
# instead of continue and return {messsage: {status:1}}
# and because of this, I cannot figure out what actually return in linked_docs
#### New code
linked_docs = get_linked_docs("Purchase Order", po_name, metadata_loaded= ["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"])
return {'status':1, 'linked_docs': linked_docs}
else:
return {'status':-1, 'error': "PO already completely delivered" }
else:
return {'status':0, 'error': "PO has not been confirmed" }
except frappe.DoesNotExistError as e:
return {'status':0, 'error': str(e) }
else:
return {'status':-1, 'error': "Missing compulsary param po_name"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment