api.py~ 1.0 KB

12345678910111213141516171819202122232425262728
  1. import json
  2. import frappe
  3. from frappe.utils.file_manager import save_url
  4. @frappe.whitelist()
  5. def attach_all_docs(document, method=None):
  6. """This function attaches drawings to the purchase order based on the items being ordered"""
  7. document = json.loads(document)
  8. count = 0
  9. for item_doc in document["items"]:
  10. item = frappe.get_doc("Item",item_doc["item_code"])
  11. attachments = []
  12. # Get the path for the attachments
  13. if item.item_attachment_1:
  14. attachments.append(item.item_attachment_1)
  15. if item.item_attachment_2:
  16. attachments.append(item.item_attachment_2)
  17. if item.item_attachment_3:
  18. attachments.append(item.item_attachment_3)
  19. if item.item_attachment_4:
  20. attachments.append(item.item_attachment_4)
  21. for attach in attachments:
  22. count = count + 1
  23. save_url(attach, document["doctype"], document["name"], "Home/Attachments")
  24. frappe.msgprint("Attached {0} files".format(count))