import json import frappe from frappe.utils.file_manager import save_url @frappe.whitelist() def attach_all_docs(document, method=None): """This function attaches drawings to the purchase order based on the items being ordered""" document = json.loads(document) count = 0 for item_doc in document["items"]: item = frappe.get_doc("Item",item_doc["item_code"]) attachments = [] # Get the path for the attachments if item.item_attachment_1: attachments.append(item.item_attachment_1) if item.item_attachment_2: attachments.append(item.item_attachment_2) if item.item_attachment_3: attachments.append(item.item_attachment_3) if item.item_attachment_4: attachments.append(item.item_attachment_4) for attach in attachments: count = count + 1 save_url(attach, document["doctype"], document["name"], "Home/Attachments") frappe.msgprint("Attached {0} files".format(count))