Skip to content

Commit

Permalink
first update
Browse files Browse the repository at this point in the history
  • Loading branch information
khushaljethava committed Nov 29, 2024
1 parent 3da09a2 commit 707cb35
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 2 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# fakeinvoicegen

# FakeInvoiceGen

A Python package that generates fake invoices using Faker and InvoiceGenerator libraries.

## Features

- Generate any number of random invoices with fake data
- Customize invoice data with your own inputs
- Easy to use API
- Configurable invoice templates

## Installation

```bash
pip install fakeinvoicegen
```

## Quick Start

```python
from fakeinvoicegen import InvoiceGenerator

# Generate 5 random invoices
generator = InvoiceGenerator()
generator.generate_invoices(count=5)

# Generate invoice with custom data
custom_data = {
'client_name': 'John Doe',
'amount': 1000.00,
'due_date': '2024-12-31'
}
generator.generate_invoice(custom_data=custom_data)
```
16 changes: 16 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configuration file for the Sphinx documentation builder.
project = 'FakeInvoiceGen'
copyright = '2024, Your Name'
author = 'Your Name'
release = '0.1.0'

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

html_theme = 'sphinx_rtd_theme'
39 changes: 39 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Welcome to FakeInvoiceGen's documentation!
===============================================

FakeInvoiceGen is a Python package that combines the power of Faker and
InvoiceGenerator libraries to create realistic fake invoices for testing and
development purposes.

.. toctree::
:maxdepth: 2
:caption: Contents:

installation
usage

Installation
-----------

You can install the package using pip:

.. code-block:: bash
pip install fakeinvoicegen
Quick Start
----------

Here's a simple example to get you started:

.. code-block:: python
from fakeinvoicegen import InvoiceGenerator
# Initialize the generator
generator = InvoiceGenerator()
# Generate 5 random invoices
generator.generate_invoices(count=5)
For more detailed information, check out the :doc:`usage` section.
31 changes: 31 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Installation
===========

Requirements
-----------

- Python 3.7 or higher
- Faker
- InvoiceGenerator

Installing with pip
-----------------

The easiest way to install FakeInvoiceGen is using pip:

.. code-block:: bash
pip install fakeinvoicegen
This will automatically install all required dependencies.

Development Installation
----------------------

If you want to contribute to the project, you can install it in development mode:

.. code-block:: bash
git clone https://github.com/yourusername/fakeinvoicegen.git
cd fakeinvoicegen
pip install -e .
48 changes: 48 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Usage
=====

Basic Usage
----------

Generate Random Invoices
~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
from fakeinvoicegen import InvoiceGenerator
# Initialize the generator
generator = InvoiceGenerator()
# Generate a single random invoice
generator.generate_invoice()
# Generate multiple random invoices
generator.generate_invoices(count=5)
Custom Invoice Data
~~~~~~~~~~~~~~~~

You can customize any aspect of the generated invoices:

.. code-block:: python
custom_data = {
'client_name': 'John Doe',
'amount': 1000.00,
'currency': 'EUR',
'due_date': '2024-12-31'
}
generator.generate_invoice(custom_data=custom_data)
API Reference
-----------

InvoiceGenerator
~~~~~~~~~~~~~~

.. autoclass:: fakeinvoicegen.InvoiceGenerator
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions fakeinvoicegen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Import the InvoiceGenerator class from generator module
from fakeinvoicegen.generator import InvoiceGenerator

# Version of the package
__version__ = '0.1.0'

# Expose InvoiceGenerator class at package level
__all__ = ['InvoiceGenerator']
Binary file added fakeinvoicegen/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
176 changes: 176 additions & 0 deletions fakeinvoicegen/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
from typing import Dict, List
from dataclasses import dataclass
from datetime import timedelta

@dataclass
class InvoiceDefaults:
"""Default values for invoice generation."""
currency: str = "USD"
payment_days: int = 30
tax_rates: List[float] = (10.0, 15.0, 20.0)
min_items: int = 1
max_items: int = 5
min_item_quantity: int = 1
max_item_quantity: int = 10
min_item_price: float = 10.0
max_item_price: float = 1000.0

@dataclass
class OutputConfig:
"""Configuration for output files."""
default_output_dir: str = "invoices"
pdf_filename_template: str = "invoice_{number}.pdf"
date_format: str = "%Y-%m-%d"

@dataclass
class LocaleConfig:
"""Configuration for localization."""
default_locale: str = "en_US"
available_locales: List[str] = ("en_US", "en_GB", "fr_FR", "de_DE", "es_ES")
date_format: str = "%Y-%m-%d"
currency_format: Dict[str, Dict] = {
"USD": {"symbol": "$", "position": "prefix"},
"EUR": {"symbol": "€", "position": "suffix"},
"GBP": {"symbol": "£", "position": "prefix"},
}

class Config:
"""Main configuration class for FakeInvoiceGen."""

def __init__(self):
self.invoice = InvoiceDefaults()
self.output = OutputConfig()
self.locale = LocaleConfig()

@property
def payment_term(self) -> timedelta:
"""Get payment term as timedelta."""
return timedelta(days=self.invoice.payment_days)

def get_currency_format(self, currency_code: str) -> Dict:
"""
Get currency formatting rules for given currency code.
Args:
currency_code (str): Currency code (e.g., 'USD', 'EUR')
Returns:
Dict: Currency formatting configuration
"""
return self.locale.currency_format.get(
currency_code,
{"symbol": currency_code, "position": "prefix"}
)

def is_supported_locale(self, locale: str) -> bool:
"""
Check if locale is supported.
Args:
locale (str): Locale code to check
Returns:
bool: True if locale is supported
"""
return locale in self.locale.available_locales

# Global configuration instance
config = Config()

# Additional configuration constants
SUPPORTED_CURRENCIES = ['USD', 'EUR', 'GBP', 'CAD', 'AUD', 'JPY']
SUPPORTED_PAYMENT_TERMS = [7, 14, 30, 45, 60, 90]

# Template configurations
INVOICE_TEMPLATES = {
'default': {
'font': 'DejaVu Sans',
'font_size': 10,
'page_size': 'A4',
'margin_top': 3,
'margin_right': 3,
'margin_bottom': 3,
'margin_left': 3,
},
'minimal': {
'font': 'DejaVu Sans',
'font_size': 9,
'page_size': 'A4',
'margin_top': 2,
'margin_right': 2,
'margin_bottom': 2,
'margin_left': 2,
},
'professional': {
'font': 'DejaVu Serif',
'font_size': 11,
'page_size': 'A4',
'margin_top': 4,
'margin_right': 3,
'margin_bottom': 4,
'margin_left': 3,
}
}

# PDF generation settings
PDF_SETTINGS = {
'compression': True,
'title_max_length': 50,
'description_max_length': 100,
'item_description_max_length': 80,
}

# Validation settings
VALIDATION_RULES = {
'min_total_amount': 0.01,
'max_total_amount': 1000000.00,
'max_items_per_invoice': 100,
'max_quantity_per_item': 1000,
'allowed_tax_rates': [0, 5, 10, 15, 20, 25],
}

def get_template_config(template_name: str = 'default') -> Dict:
"""
Get configuration for specified template.
Args:
template_name (str): Name of the template to use
Returns:
Dict: Template configuration
"""
return INVOICE_TEMPLATES.get(template_name, INVOICE_TEMPLATES['default'])

def validate_currency(currency: str) -> bool:
"""
Validate if currency is supported.
Args:
currency (str): Currency code to validate
Returns:
bool: True if currency is supported
"""
return currency in SUPPORTED_CURRENCIES

def validate_payment_term(days: int) -> bool:
"""
Validate if payment term is supported.
Args:
days (int): Number of days for payment term
Returns:
bool: True if payment term is supported
"""
return days in SUPPORTED_PAYMENT_TERMS

# Error messages
ERROR_MESSAGES = {
'invalid_currency': 'Invalid currency code. Supported currencies are: {currencies}',
'invalid_payment_term': 'Invalid payment term. Supported terms are: {terms} days',
'invalid_template': 'Invalid template name. Available templates are: {templates}',
'invalid_locale': 'Invalid locale. Supported locales are: {locales}',
'invalid_amount': 'Total amount must be between {min_amount} and {max_amount}',
'too_many_items': 'Number of items exceeds maximum limit of {max_items}',
}
Loading

0 comments on commit 707cb35

Please sign in to comment.