import datetime import random import string def generate_invoice_number(prefix="INV", length=6): """ Generate a unique invoice number. Format: INV-{YEAR}{MONTH}-{RANDOM_ALPHANUMERIC} Example: INV-202307-A1B2C3 Args: prefix (str): Prefix for the invoice number length (int): Length of the random string Returns: str: Generated invoice number """ # Get current date for year-month part today = datetime.datetime.now() year_month = today.strftime("%Y%m") # Generate random alphanumeric string characters = string.ascii_uppercase + string.digits random_str = ''.join(random.choice(characters) for _ in range(length)) # Combine to form invoice number invoice_number = f"{prefix}-{year_month}-{random_str}" return invoice_number def calculate_total_amount(items): """ Calculate the total amount of an invoice based on its items. Args: items (list): List of invoice items, each with quantity and unit_price Returns: float: Total amount """ total = 0.0 for item in items: item_amount = item.quantity * item.unit_price total += item_amount return total