fixes after rebase

This commit is contained in:
Richard Kubíček
2025-02-28 18:00:49 +01:00
parent 84f5cd8642
commit ff7ab2ba9a
5 changed files with 105 additions and 25 deletions

View File

@@ -4,31 +4,31 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath("../.."))
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'SuperFaktura API client'
copyright = '2025, Richard Kubíček, Eledio s.r.o.'
author = 'Richard Kubíček'
project = "SuperFaktura API client"
copyright = "2025, Richard Kubíček, Eledio s.r.o."
author = "Richard Kubíček"
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.autosummary',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.autosummary",
]
templates_path = ['_templates']
templates_path = ["_templates"]
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]

View File

@@ -1,6 +1,32 @@
"""
Data Format Enumeration.
This module provides an enumeration of data formats that can be used in the SuperFaktura API.
Classes:
- DataFormat: Enumeration of data formats.
Usage:
from superfaktura.enumerations.data_format import DataFormat
data_format = DataFormat.JSON
"""
import enum
class DataFormat(enum.Enum):
"""
Data Format Enumeration.
This enumeration represents the different data formats that can be used in the SuperFaktura API.
Values:
- JSON: JSON format
- PDF: PDF format
Usage:
data_format = DataFormat.JSON
"""
JSON = enum.auto()
PDF = enum.auto()

View File

@@ -1,4 +1,43 @@
"""
Language Enumeration.
This module provides an enumeration of languages that can be used in the SuperFaktura API.
Classes:
- Language: Enumeration of languages.
Usage:
from superfaktura.enumerations.language import Language
language = Language.Czech
"""
class Language:
"""
Language Enumeration.
This enumeration represents the different languages that can be used in the SuperFaktura API.
Values:
- Czech: Czech
- German: German
- English: English
- Croatian: Croatian
- Hungarian: Hungarian
- Italian: Italian
- Dutch: Dutch
- Polish: Polish
- Romanian: Romanian
- Russian: Russian
- Slovak: Slovak
- Slovene: Slovene
- Spanish: Spanish
- Ukrainian: Ukrainian
Usage:
language = Language.Czech
"""
Czech = "cze"
German = "deu"
English = "eng"

View File

@@ -52,6 +52,7 @@ Usage:
)
"""
import tempfile
from dataclasses import dataclass, asdict
from typing import Optional, List, IO
import json
@@ -152,6 +153,16 @@ class InvoiceItem:
@dataclass
class InvoiceRespModel:
"""
This dataclass represents the response model for an invoice in the SuperFaktura API.
Attributes:
- error (int): The error code.
- error_message (str): The error message.
- invoice_id (Optional[int]): The ID of the invoice.
- invoice_token (Optional[str]): The token of
"""
error: int
error_message: str
invoice_id: Optional[int] = None
@@ -159,7 +170,7 @@ class InvoiceRespModel:
class InvoiceType:
""" "
"""
Invoice Type Enumeration.
This enumeration represents the different types of invoices that can be created.
@@ -228,12 +239,15 @@ class Invoice(SuperFakturaAPI):
Adds a new invoice.
Args:
invoice (InvoiceModel): The invoice model.
invoice_model (InvoiceModel): The invoice model.
items (List[InvoiceItem]): List of invoice items.
contact (ClientContactModel): The client contact model.
Returns:
InvoiceRespModel: The response model for the invoice.
:param contact:
:param items:
:param invoice_model:
"""
data = {
"Invoice": invoice_model.as_dict(),
@@ -278,8 +292,8 @@ if __name__ == "__main__":
resp = invoice.add(
invoice_model=InvoiceModel(
type=InvoiceType.PROFORMA,
name="Invoice 5",
due=Date("2025-02-01"),
name="Invoice 8",
due=Date("2025-04-01"),
invoice_currency=Currencies.CZK,
header_comment="We invoice you for services",
bank_accounts=[bank.default().as_dict()],

View File

@@ -39,7 +39,6 @@ class SuperFakturaAPIException(Exception):
"""Exception for errors when working with the SuperFaktura API."""
class SuperFakturaAPIMissingCredentialsException(Exception):
"""Exception for missing login credentials."""
@@ -65,7 +64,9 @@ class SuperFakturaAPI:
f"{_api_company_id}"
}
def get(self, endpoint: str, data_format: DataFormat = DataFormat.JSON, timeout: int = 5) -> Dict:
def get(
self, endpoint: str, data_format: DataFormat = DataFormat.JSON, timeout: int = 5
) -> Dict:
"""
Retrieves data from the SuperFaktura API.
@@ -97,10 +98,11 @@ class SuperFakturaAPI:
return req.json()
elif data_format == DataFormat.PDF:
return {"pdf": req.content} # returns a dict with the PDF content
else:
raise SuperFakturaAPIException(
f"Get status code: {req.status_code}; {req.json()}"
)
else:
raise SuperFakturaAPIException("Invalid data format")
raise SuperFakturaAPIException(
f"Get status code: {req.status_code}; {req.json()}"
)
def post(self, endpoint: str, data: str, timeout: int = 5) -> Dict:
"""
@@ -137,7 +139,6 @@ class SuperFakturaAPI:
)
if req.status_code == 200:
return req.json()
else:
raise SuperFakturaAPIException(
f"Post status code: {req.status_code}; {req.json()}"
)
raise SuperFakturaAPIException(
f"Post status code: {req.status_code}; {req.json()}"
)