Last active
August 29, 2015 14:04
-
-
Save nathando/a37ba1d64945e1b07c99 to your computer and use it in GitHub Desktop.
Custome API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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