def get_attachments(self): attachments = [ d.name for d in get_attachments(self.doctype, self.name) ] attachments.append( dataent.attach_print(self.doctype, self.name, doc=self)) return attachments
def copy_attachments_from_amended_from(self): '''Copy attachments from `amended_from`''' from dataent.desk.form.load import get_attachments #loop through attachments for attach_item in get_attachments(self.doctype, self.amended_from): #save attachments to new doc save_url(attach_item.file_url, attach_item.file_name, self.doctype, self.name, "Home/Attachments", attach_item.is_private)
def get_e_invoice_attachments(invoice): if not invoice.company_tax_id: return [] out = [] attachments = get_attachments(invoice.doctype, invoice.name) company_tax_id = invoice.company_tax_id if invoice.company_tax_id.startswith( "IT") else "IT" + invoice.company_tax_id for attachment in attachments: if attachment.file_name and attachment.file_name.startswith( company_tax_id) and attachment.file_name.endswith(".xml"): out.append(attachment) return out
def test_incoming_with_attach(self): dataent.db.sql( "delete from tabCommunication where sender='*****@*****.**'" ) existing_file = dataent.get_doc({ 'doctype': 'File', 'file_name': 'epaas-conf-14.png' }) dataent.delete_doc("File", existing_file.name) delete_file_from_filesystem(existing_file) with open( os.path.join(os.path.dirname(__file__), "test_mails", "incoming-2.raw"), "r") as testfile: test_mails = [testfile.read()] email_account = dataent.get_doc("Email Account", "_Test Email Account 1") email_account.receive(test_mails=test_mails) comm = dataent.get_doc("Communication", {"sender": "*****@*****.**"}) self.assertTrue("*****@*****.**" in comm.recipients) # check attachment attachments = get_attachments(comm.doctype, comm.name) self.assertTrue( "epaas-conf-14.png" in [f.file_name for f in attachments]) # cleanup existing_file = dataent.get_doc({ 'doctype': 'File', 'file_name': 'epaas-conf-14.png' }) dataent.delete_doc("File", existing_file.name) delete_file_from_filesystem(existing_file)
def prepare_item(item): item.source_type = "local" item.attachments = get_attachments('Item', item.item_code) return item
def download_attachment(dn): attachment = get_attachments("Prepared Report", dn)[0] dataent.local.response.filename = attachment.file_name[:-2] dataent.local.response.filecontent = gzip_decompress( get_file(attachment.name)[1]) dataent.local.response.type = "binary"