Skip to content

Commit

Permalink
✨ Handling NoSuchInvoice from erp, and dummy for pdf errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Dec 28, 2023
1 parent b4095aa commit bc5149b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/datasources/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ContractNotExists,
UnauthorizedAccess,
NoSuchUser,
NoSuchInvoice,
NoDocumentVersions,
)

Expand Down Expand Up @@ -210,10 +211,31 @@ def dummy_installation_details(username: str, contract_number: str) -> Installat
))
return InstallationDetailsResult(**ns.load('frontend/src/data/dummyinstallationdetail.yaml'))

invoice_pdf_exceptions = {
e.__name__: e
for e in [
UnauthorizedAccess,
NoSuchUser,
NoSuchInvoice,
ErpValidationError,
# TODO: ErpConnectionError,
# TODO: ErpUnexpectedError,
]
}

def dummy_invoices(username: str) -> list[Invoice]:
return [
Invoice(**invoice)
for invoice in ns.load('frontend/src/data/dummyinvoices.yaml')
]+[
Invoice(
invoice_number=name,
contract_number='10002',
emission_date='2020-01-01',
first_period_date='2020-01-01',
last_period_date='2020-01-01',
amount=200,
) for name in invoice_pdf_exceptions.keys()
]

def pdf_content(invoice_number):
Expand All @@ -231,6 +253,11 @@ def pdf_content(invoice_number):
return output.getvalue()

def dummy_invoice_pdf(username: str, invoice_number: str):
if invoice_number in invoice_pdf_exceptions:
raise invoice_pdf_exceptions[invoice_number](dict(
code=invoice_number,
error=f"{invoice_number} (Dummy error)",
))
base64_data = base64.b64encode(Path('/usr/share/doc/tig/manual.pdf').read_bytes())
base64_data = base64.b64encode(pdf_content(invoice_number))
return InvoicePdf(
Expand Down
2 changes: 2 additions & 0 deletions backend/datasources/erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ContractNotExists,
UnauthorizedAccess,
NoSuchUser,
NoSuchInvoice,
NoDocumentVersions,
)
from .dummy import dummy_invoice_pdf
Expand All @@ -36,6 +37,7 @@ def catch_validation_error():
ContractNotExists,
UnauthorizedAccess,
NoSuchUser,
NoSuchInvoice,
NoDocumentVersions,
]
def process_erp_errors(erp_response):
Expand Down
3 changes: 3 additions & 0 deletions backend/datasources/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ class UnauthorizedAccess(ErpError):
class NoSuchUser(ErpError):
pass

class NoSuchInvoice(ErpError):
pass

class NoDocumentVersions(ErpError):
pass

0 comments on commit bc5149b

Please sign in to comment.