From 652d035ecde4a6a43f061ee4d24321fc244fe21d Mon Sep 17 00:00:00 2001 From: Nil Villarroya Date: Tue, 11 Jun 2024 16:18:41 +0200 Subject: [PATCH] new method send_by_file --- face/services/invoice.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/face/services/invoice.py b/face/services/invoice.py index 19a4d15..730bde7 100644 --- a/face/services/invoice.py +++ b/face/services/invoice.py @@ -27,18 +27,23 @@ def fetch(self, invoice): else: return call_result - def send(self, invoice, attachments=None): + def send_by_filename(self, invoice, attachments=None): + assert type(invoice) == str, "Invoice must be the filename of the invoice to deliver" + invoice_content = base64.b64encode(open(invoice).read()) + invoice_filename = os.path.basename(invoice) + return self.send(invoice_filename, invoice_content, attachments=attachments) + + def send(self, invoice_filename, invoice_content, attachments=None): """ Send an invoice with optional attachments and return the delivery result It prepares the payload wanted for the `enviarFactura` webservice with a base64 invoice and their filename """ - assert type(invoice) == str, "Invoice must be the filename of the invoice to deliver" the_invoice = { "correo": self.email, "factura": { - "factura": base64.b64encode(open(invoice).read()), - "nombre": os.path.basename(invoice), + "factura": invoice_content, + "nombre": invoice_filename, "mime": "application/xml", } }