mirror of
				https://github.com/Eledio/superfaktura-client.git
				synced 2025-10-31 08:22:32 +01:00 
			
		
		
		
	Project rearrange
This commit is contained in:
		| @@ -6,7 +6,7 @@ from superfaktura.bank_account import BankAccount | ||||
| from superfaktura.client_contacts import ClientContactModel | ||||
| from superfaktura.enumerations.currency import Currencies | ||||
| from superfaktura.superfaktura_api import SuperFakturaAPI | ||||
| from utils.data_types import Date, DateEncoder | ||||
| from superfaktura.utils.data_types import Date, DateEncoder | ||||
|  | ||||
|  | ||||
| @dataclass | ||||
|   | ||||
							
								
								
									
										0
									
								
								superfaktura/utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								superfaktura/utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										12
									
								
								superfaktura/utils/country.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								superfaktura/utils/country.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| from pprint import pprint | ||||
|  | ||||
| from superfaktura.superfaktura_api import SuperFakturaAPI | ||||
|  | ||||
|  | ||||
| def country_list(): | ||||
|     api = SuperFakturaAPI() | ||||
|     url = "countries" | ||||
|     return api.get(url) | ||||
|  | ||||
|  | ||||
| pprint(country_list()) | ||||
							
								
								
									
										62
									
								
								superfaktura/utils/data_types.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								superfaktura/utils/data_types.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| from datetime import datetime | ||||
| from typing import Optional | ||||
|  | ||||
| import json | ||||
|  | ||||
|  | ||||
| class Date: | ||||
|     def __init__(self, date_str: Optional[str] = None): | ||||
|         """ | ||||
|         Creates a Date instance that supports typing and validation for the format YYYY-MM-DD. | ||||
|  | ||||
|         :param date_str: Date in the format YYYY-MM-DD or None. | ||||
|         """ | ||||
|         self.date: Optional[datetime] = None | ||||
|         if date_str: | ||||
|             self.date = self._validate_date(date_str) | ||||
|  | ||||
|     @staticmethod | ||||
|     def _validate_date(date_str: str) -> datetime: | ||||
|         """ | ||||
|         Validates that the date is in the format YYYY-MM-DD. | ||||
|  | ||||
|         :param date_str: Date as a string. | ||||
|         :return: Validated date as a datetime instance. | ||||
|         """ | ||||
|         try: | ||||
|             return datetime.strptime(date_str, "%Y-%m-%d") | ||||
|         except ValueError: | ||||
|             raise ValueError(f"Date must be in format YYYY-MM-DD, got: {date_str}") | ||||
|  | ||||
|     def __str__(self) -> str: | ||||
|         """ | ||||
|         Returns the date as a string in the format YYYY-MM-DD, or 'None' if not set. | ||||
|         """ | ||||
|         return self.date.strftime("%Y-%m-%d") if self.date else "None" | ||||
|  | ||||
|     def is_set(self) -> bool: | ||||
|         """ | ||||
|         Returns True if the date is set, otherwise False. | ||||
|         """ | ||||
|         return self.date is not None | ||||
|  | ||||
|     def to_dict(self) -> Optional[str]: | ||||
|         """ | ||||
|         Converts the Date object to a serializable format. | ||||
|         :return: The date as a string in YYYY-MM-DD format, or None if not set. | ||||
|         """ | ||||
|         return self.date.strftime("%Y-%m-%d") if self.date else None | ||||
|  | ||||
|     def to_json(self) -> Optional[str]: | ||||
|         """ | ||||
|         Converts the Date object to a JSON serializable format. | ||||
|         :return: The date as a string in YYYY-MM-DD format, or None if not set. | ||||
|         """ | ||||
|         return self.to_dict() | ||||
|  | ||||
|  | ||||
| class DateEncoder(json.JSONEncoder): | ||||
|     def default(self, o): | ||||
|         if isinstance(o, Date): | ||||
|             return o.to_json() | ||||
|         return super().default(o) | ||||
		Reference in New Issue
	
	Block a user