Skip to content

Commit

Permalink
new method send_by_file
Browse files Browse the repository at this point in the history
  • Loading branch information
nvillarroya committed Jun 11, 2024
1 parent 85392ab commit 652d035
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions face/services/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
Expand Down

0 comments on commit 652d035

Please sign in to comment.