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 # https://www.sphinx-doc.org/en/master/usage/configuration.html
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath("../.."))
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'SuperFaktura API client' project = "SuperFaktura API client"
copyright = '2025, Richard Kubíček, Eledio s.r.o.' copyright = "2025, Richard Kubíček, Eledio s.r.o."
author = 'Richard Kubíček' author = "Richard Kubíček"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [ extensions = [
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.napoleon', "sphinx.ext.napoleon",
'sphinx.ext.autosummary', "sphinx.ext.autosummary",
] ]
templates_path = ['_templates'] templates_path = ["_templates"]
exclude_patterns = [] exclude_patterns = []
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'sphinx_rtd_theme' html_theme = "sphinx_rtd_theme"
html_static_path = ['_static'] 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 import enum
class DataFormat(enum.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() JSON = enum.auto()
PDF = 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: 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" Czech = "cze"
German = "deu" German = "deu"
English = "eng" English = "eng"

View File

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

View File

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