mirror of
https://github.com/Eledio/superfaktura-client.git
synced 2025-11-01 00:18:25 +01:00
bank_account: fix module by pylint hints
This commit is contained in:
@@ -1,3 +1,36 @@
|
|||||||
|
"""
|
||||||
|
Bank Account Module.
|
||||||
|
|
||||||
|
This module provides classes and functions for working with bank accounts in the SuperFaktura API.
|
||||||
|
It allows for retrieving, creating, updating, and deleting bank accounts.
|
||||||
|
|
||||||
|
Classes:
|
||||||
|
- BankAccountModel: Dataclass representing a bank account.
|
||||||
|
- BankAccount: Class for interacting with bank accounts.
|
||||||
|
|
||||||
|
Exceptions:
|
||||||
|
- NoDefaultBankAccountException: Exception for when no default bank account is found.
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
- (none)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
import superfaktura.bank_account
|
||||||
|
|
||||||
|
# Create an instance of BankAccount
|
||||||
|
bank = superfaktura.bank_account.BankAccount()
|
||||||
|
|
||||||
|
# Retrieve a list of bank accounts
|
||||||
|
accounts = bank.list()
|
||||||
|
|
||||||
|
# Get the default bank account
|
||||||
|
default_account = bank.default()
|
||||||
|
|
||||||
|
# Create or update a bank account
|
||||||
|
data = {"account": "1234567890", "bank_code": "1234567890", "default": True}
|
||||||
|
bank.post(data)
|
||||||
|
"""
|
||||||
|
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@@ -5,11 +38,13 @@ from superfaktura.superfaktura_api import SuperFakturaAPI
|
|||||||
|
|
||||||
|
|
||||||
class NoDefaultBankAccountException(Exception):
|
class NoDefaultBankAccountException(Exception):
|
||||||
pass
|
"""Exception for when no default bank account is found."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BankAccountModel:
|
class BankAccountModel:
|
||||||
|
"""Dataclass representing a bank account."""
|
||||||
|
|
||||||
account: Optional[str]
|
account: Optional[str]
|
||||||
bank_code: Optional[str]
|
bank_code: Optional[str]
|
||||||
bank_name: Optional[str]
|
bank_name: Optional[str]
|
||||||
@@ -20,6 +55,7 @@ class BankAccountModel:
|
|||||||
id: Optional[int]
|
id: Optional[int]
|
||||||
|
|
||||||
def as_dict(self) -> dict:
|
def as_dict(self) -> dict:
|
||||||
|
"""Returns a dictionary representation of the BankAccountModel."""
|
||||||
data = asdict(self)
|
data = asdict(self)
|
||||||
for key in list(data.keys()):
|
for key in list(data.keys()):
|
||||||
if data[key] is None:
|
if data[key] is None:
|
||||||
@@ -28,24 +64,42 @@ class BankAccountModel:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(data: dict) -> "BankAccountModel":
|
def from_dict(data: dict) -> "BankAccountModel":
|
||||||
|
"""Creates a BankAccountModel from a dictionary."""
|
||||||
return BankAccountModel(
|
return BankAccountModel(
|
||||||
**{
|
**{k: v for k, v in data.items() if k in BankAccountModel.__annotations__}
|
||||||
k: v
|
|
||||||
for k, v in data.items()
|
|
||||||
if k in BankAccountModel.__dataclass_fields__
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BankAccount(SuperFakturaAPI):
|
class BankAccount(SuperFakturaAPI):
|
||||||
|
"""
|
||||||
|
Bank Account Class.
|
||||||
|
|
||||||
|
This class provides methods for interacting with bank accounts in the SuperFaktura API.
|
||||||
|
It allows for retrieving, creating, updating, and deleting bank accounts.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
- list: Retrieves a list of bank accounts.
|
||||||
|
- default: Retrieves the default bank account.
|
||||||
|
- post: Creates or updates a bank account.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
bank = BankAccount()
|
||||||
|
accounts = bank.list()
|
||||||
|
default_account = bank.default()
|
||||||
|
data = {"account": "1234567890", "bank_code": "1234567890", "default": True}
|
||||||
|
bank.post(data)
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def list(self) -> dict:
|
def list(self) -> dict:
|
||||||
|
"""Retrieves a list of bank accounts."""
|
||||||
url = "bank_accounts/index"
|
url = "bank_accounts/index"
|
||||||
return self.get(url)
|
return self.get(url)
|
||||||
|
|
||||||
def default(self) -> Optional[BankAccountModel]:
|
def default(self) -> Optional[BankAccountModel]:
|
||||||
|
"""Retrieves the default bank account."""
|
||||||
accounts = self.list()["BankAccounts"]
|
accounts = self.list()["BankAccounts"]
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
if account["BankAccount"]["default"]:
|
if account["BankAccount"]["default"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user