mirror of
https://github.com/Eledio/superfaktura-client.git
synced 2025-11-01 08:28:25 +01:00
invoice: do not use tempfile
This commit is contained in:
@@ -52,9 +52,8 @@ Usage:
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import tempfile
|
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from typing import Optional, List, IO
|
from typing import Optional, List
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from superfaktura.bank_account import BankAccount
|
from superfaktura.bank_account import BankAccount
|
||||||
@@ -267,7 +266,7 @@ class Invoice(SuperFakturaAPI):
|
|||||||
|
|
||||||
def get_pdf(
|
def get_pdf(
|
||||||
self, invoice: InvoiceRespModel, language: str = Language.Czech
|
self, invoice: InvoiceRespModel, language: str = Language.Czech
|
||||||
) -> IO[bytes]:
|
) -> bytes:
|
||||||
"""
|
"""
|
||||||
Retrieves the PDF of the invoice.
|
Retrieves the PDF of the invoice.
|
||||||
|
|
||||||
@@ -276,14 +275,11 @@ class Invoice(SuperFakturaAPI):
|
|||||||
language (str): The language for the PDF.
|
language (str): The language for the PDF.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
IO[bytes]: A file-like object containing the PDF data.
|
bytes: A bytes containing the PDF data.
|
||||||
"""
|
"""
|
||||||
url = f"{language}/invoices/pdf/{invoice.invoice_id}/token:{invoice.invoice_token}"
|
url = f"{language}/invoices/pdf/{invoice.invoice_id}/token:{invoice.invoice_token}"
|
||||||
document = self.get(url, data_format=DataFormat.PDF)["pdf"]
|
document = self.get(url, data_format=DataFormat.PDF)["pdf"]
|
||||||
temp_pdf = tempfile.TemporaryFile()
|
return document
|
||||||
temp_pdf.write(document)
|
|
||||||
temp_pdf.seek(0)
|
|
||||||
return temp_pdf
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user