mirror of
				https://github.com/Eledio/superfaktura-client.git
				synced 2025-10-31 16:11:20 +01:00 
			
		
		
		
	examples: add get_country_list and add_invoice
This commit is contained in:
		
							
								
								
									
										72
									
								
								examples/add_invoice.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								examples/add_invoice.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| """ | ||||
| Main script to add an invoice and save it as a PDF using the SuperFaktura API. | ||||
|  | ||||
| This script demonstrates how to create an invoice with multiple items, | ||||
| retrieve the invoice as a PDF, and save the PDF to a file. | ||||
|  | ||||
| Usage: | ||||
|     Run this script directly to create and save an invoice PDF. | ||||
|  | ||||
| Dependencies: | ||||
|     - examples.tools.save_file_as_pdf | ||||
|     - superfaktura.bank_account.BankAccount | ||||
|     - superfaktura.client_contacts.ClientContactModel | ||||
|     - superfaktura.enumerations.currency.Currencies | ||||
|     - superfaktura.enumerations.language.Language | ||||
|     - superfaktura.invoice.Invoice | ||||
|     - superfaktura.invoice.InvoiceModel | ||||
|     - superfaktura.invoice.InvoiceType | ||||
|     - superfaktura.invoice.InvoiceItem | ||||
|     - superfaktura.invoice.InvoiceSettings | ||||
|     - superfaktura.utils.data_types.Date | ||||
| """ | ||||
|  | ||||
| from examples.tools import save_file_as_pdf | ||||
| from superfaktura.bank_account import BankAccount | ||||
| from superfaktura.client_contacts import ClientContactModel | ||||
| from superfaktura.enumerations.currency import Currencies | ||||
| from superfaktura.enumerations.language import Language | ||||
| from superfaktura.invoice import ( | ||||
|     Invoice, | ||||
|     InvoiceModel, | ||||
|     InvoiceType, | ||||
|     InvoiceItem, | ||||
|     InvoiceSettings, | ||||
| ) | ||||
| from superfaktura.utils.data_types import Date | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     invoice = Invoice() | ||||
|     bank = BankAccount() | ||||
|     resp = invoice.add( | ||||
|         invoice_model=InvoiceModel( | ||||
|             type=InvoiceType.INVOICE, | ||||
|             name="My First Invoice", | ||||
|             due=Date("2025-04-01"), | ||||
|             invoice_currency=Currencies.EUR, | ||||
|             header_comment="We invoice you for services", | ||||
|             bank_accounts=[bank.default().as_dict()], | ||||
|         ), | ||||
|         items=[ | ||||
|             InvoiceItem( | ||||
|                 name="Website Development", unit_price=1000.0, quantity=1, tax=20 | ||||
|             ), | ||||
|             InvoiceItem( | ||||
|                 name="Hosting Service (1 year)", unit_price=500.0, quantity=1, tax=20 | ||||
|             ), | ||||
|         ], | ||||
|         contact=ClientContactModel( | ||||
|             name="John Doe", | ||||
|             email="john.doe@examle.com", | ||||
|             phone="+1 555-1234", | ||||
|             address="123 Main Street, New York", | ||||
|             ico="987654321", | ||||
|             update=True, | ||||
|             country_id=225, | ||||
|         ), | ||||
|         invoice_settings=InvoiceSettings(language=Language.English), | ||||
|     ) | ||||
|     _pdf = invoice.get_pdf(invoice=resp, language=Language.English) | ||||
|  | ||||
|     save_file_as_pdf(_pdf, "invoice.pdf") | ||||
							
								
								
									
										18
									
								
								examples/get_country_list.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								examples/get_country_list.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| """ | ||||
| This script retrieves and prints the list of countries using the SuperFaktura API. | ||||
| """ | ||||
|  | ||||
| from pprint import pprint | ||||
|  | ||||
| from superfaktura.utils.country import country_list | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     """ | ||||
|     Main function to retrieve and print the list of countries using the SuperFaktura API. | ||||
|     """ | ||||
|     pprint(country_list()) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     main() | ||||
| @@ -1,7 +1,14 @@ | ||||
| """ | ||||
| This module contains tools for working with these examples. | ||||
| """ | ||||
|  | ||||
|  | ||||
| def save_file_as_pdf( | ||||
|     input_data: bytes, output_path: str = "output.pdf" | ||||
| ) -> None: | ||||
| def save_file_as_pdf(input_data: bytes, output_path: str = "output.pdf") -> None: | ||||
|     """ | ||||
|     Save the input data as a PDF file. | ||||
|     :param input_data: | ||||
|     :param output_path: | ||||
|     :return: | ||||
|     """ | ||||
|     with open(output_path, "wb") as f: | ||||
|         f.write(input_data) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user