mirror of
https://github.com/Eledio/superfaktura-client.git
synced 2025-11-01 00:18:25 +01:00
client_contacts: fix module by pylint hints
This commit is contained in:
@@ -1,3 +1,24 @@
|
||||
"""
|
||||
Module for interacting with client contacts in SuperFaktura.
|
||||
|
||||
This module provides classes and functions for working with client contacts,
|
||||
including creating, reading, and updating contact information.
|
||||
|
||||
Classes:
|
||||
ClientException: Base class for client exceptions.
|
||||
ClientContactModel: Dataclass representing a client contact.
|
||||
|
||||
Functions:
|
||||
(none)
|
||||
|
||||
Variables:
|
||||
(none)
|
||||
|
||||
Notes:
|
||||
This module uses the SuperFaktura API to interact with client contacts.
|
||||
You must have a valid API key and credentials to use this module.
|
||||
"""
|
||||
|
||||
import dataclasses
|
||||
import json
|
||||
from pprint import pprint
|
||||
@@ -7,11 +28,13 @@ from superfaktura.superfaktura_api import SuperFakturaAPI
|
||||
|
||||
|
||||
class ClientException(Exception):
|
||||
pass
|
||||
"""Base class for client exceptions."""
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class ClientContactModel:
|
||||
"""Client contact model."""
|
||||
|
||||
name: str
|
||||
address: Optional[str] = None
|
||||
bank_account: Optional[str] = None
|
||||
@@ -48,6 +71,7 @@ class ClientContactModel:
|
||||
id: Optional[int] = None
|
||||
|
||||
def as_dict(self) -> dict:
|
||||
"""Returns a dictionary representation of the ClientContactModel."""
|
||||
data = dataclasses.asdict(self)
|
||||
for key in list(data.keys()):
|
||||
if data[key] is None:
|
||||
@@ -56,32 +80,34 @@ class ClientContactModel:
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: dict) -> "ClientContactModel":
|
||||
"""Creates a ClientContactModel from a dictionary."""
|
||||
return ClientContactModel(
|
||||
**{
|
||||
k: v
|
||||
for k, v in data.items()
|
||||
if k in ClientContactModel.__dataclass_fields__
|
||||
}
|
||||
**{k: v for k, v in data.items() if k in ClientContactModel.__annotations__}
|
||||
)
|
||||
|
||||
|
||||
class ClientContact(SuperFakturaAPI):
|
||||
"""Client contact class."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def add_contact(self, contact: ClientContactModel) -> bool:
|
||||
"""Adds a new client contact."""
|
||||
url = "clients/create"
|
||||
data = {"Client": contact.as_dict()}
|
||||
resp = self.post(endpoint=url, data=json.dumps(data))
|
||||
if resp["error_message"] == "Client created":
|
||||
response = self.post(endpoint=url, data=json.dumps(data))
|
||||
if response["error_message"] == "Client created":
|
||||
return True
|
||||
return False
|
||||
|
||||
def list(self) -> dict:
|
||||
"""Lists all exists client contacts."""
|
||||
url = "clients/index.json"
|
||||
return self.get(endpoint=url)
|
||||
|
||||
def get_client(self, client_id: int) -> ClientContactModel:
|
||||
"""Gets a client contact by ID."""
|
||||
url = f"clients/view/{client_id}"
|
||||
data = self.get(endpoint=url)
|
||||
if "Client" not in data:
|
||||
|
||||
Reference in New Issue
Block a user