mirror of
				https://github.com/Eledio/superfaktura-client.git
				synced 2025-10-31 16:11:20 +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 dataclasses | ||||||
| import json | import json | ||||||
| from pprint import pprint | from pprint import pprint | ||||||
| @@ -7,11 +28,13 @@ from superfaktura.superfaktura_api import SuperFakturaAPI | |||||||
|  |  | ||||||
|  |  | ||||||
| class ClientException(Exception): | class ClientException(Exception): | ||||||
|     pass |     """Base class for client exceptions.""" | ||||||
|  |  | ||||||
|  |  | ||||||
| @dataclasses.dataclass | @dataclasses.dataclass | ||||||
| class ClientContactModel: | class ClientContactModel: | ||||||
|  |     """Client contact model.""" | ||||||
|  |  | ||||||
|     name: str |     name: str | ||||||
|     address: Optional[str] = None |     address: Optional[str] = None | ||||||
|     bank_account: Optional[str] = None |     bank_account: Optional[str] = None | ||||||
| @@ -48,6 +71,7 @@ class ClientContactModel: | |||||||
|     id: Optional[int] = None |     id: Optional[int] = None | ||||||
|  |  | ||||||
|     def as_dict(self) -> dict: |     def as_dict(self) -> dict: | ||||||
|  |         """Returns a dictionary representation of the ClientContactModel.""" | ||||||
|         data = dataclasses.asdict(self) |         data = dataclasses.asdict(self) | ||||||
|         for key in list(data.keys()): |         for key in list(data.keys()): | ||||||
|             if data[key] is None: |             if data[key] is None: | ||||||
| @@ -56,32 +80,34 @@ class ClientContactModel: | |||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def from_dict(data: dict) -> "ClientContactModel": |     def from_dict(data: dict) -> "ClientContactModel": | ||||||
|  |         """Creates a ClientContactModel from a dictionary.""" | ||||||
|         return ClientContactModel( |         return ClientContactModel( | ||||||
|             **{ |             **{k: v for k, v in data.items() if k in ClientContactModel.__annotations__} | ||||||
|                 k: v |  | ||||||
|                 for k, v in data.items() |  | ||||||
|                 if k in ClientContactModel.__dataclass_fields__ |  | ||||||
|             } |  | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |  | ||||||
| class ClientContact(SuperFakturaAPI): | class ClientContact(SuperFakturaAPI): | ||||||
|  |     """Client contact class.""" | ||||||
|  |  | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         super().__init__() |         super().__init__() | ||||||
|  |  | ||||||
|     def add_contact(self, contact: ClientContactModel) -> bool: |     def add_contact(self, contact: ClientContactModel) -> bool: | ||||||
|  |         """Adds a new client contact.""" | ||||||
|         url = "clients/create" |         url = "clients/create" | ||||||
|         data = {"Client": contact.as_dict()} |         data = {"Client": contact.as_dict()} | ||||||
|         resp = self.post(endpoint=url, data=json.dumps(data)) |         response = self.post(endpoint=url, data=json.dumps(data)) | ||||||
|         if resp["error_message"] == "Client created": |         if response["error_message"] == "Client created": | ||||||
|             return True |             return True | ||||||
|         return False |         return False | ||||||
|  |  | ||||||
|     def list(self) -> dict: |     def list(self) -> dict: | ||||||
|  |         """Lists all exists client contacts.""" | ||||||
|         url = "clients/index.json" |         url = "clients/index.json" | ||||||
|         return self.get(endpoint=url) |         return self.get(endpoint=url) | ||||||
|  |  | ||||||
|     def get_client(self, client_id: int) -> ClientContactModel: |     def get_client(self, client_id: int) -> ClientContactModel: | ||||||
|  |         """Gets a client contact by ID.""" | ||||||
|         url = f"clients/view/{client_id}" |         url = f"clients/view/{client_id}" | ||||||
|         data = self.get(endpoint=url) |         data = self.get(endpoint=url) | ||||||
|         if "Client" not in data: |         if "Client" not in data: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user