Overview
The inventory management system consists of 6 core modules, each providing specific functionality in the ETL pipeline:loader
Data extraction from Excel files
analisis
ABC classification algorithm
decisiones
Risk evaluation and replenishment logic
reportes
Excel report generation
reportes_graficos
Chart and visualization generation
emailer
Email delivery service
loader
Module:
loader.py | Purpose: Extract inventory data from Excel filescargar_inventario()
Loads inventory data from an Excel file into a pandas DataFrame.Absolute or relative path to the Excel inventory fileExample:
"data/inventario.xlsx"DataFrame containing the loaded inventory dataExpected columns:
stock_actual: Current stock quantitystock_minimo: Minimum acceptable stock levelventas_mensuales: Average monthly sales volume- Additional product metadata (name, ID, etc.)
Raised if the file cannot be read or parsedError message includes the underlying exception details
Usage Example
Source Code
analisis
Module:
analisis.py | Purpose: Perform ABC classification analysisclasificacion_abc()
Classifies products using the ABC method based on cumulative sales contribution.DataFrame containing inventory data with a
ventas_mensuales columnRequired column: ventas_mensuales (monthly sales volume)DataFrame with two new columns added:
porcentaje_acumulado: Cumulative sales percentage (0.0 to 1.0)categoria_abc: Category assignment (“A”, “B”, or “C”)
.copy())Classification Logic
- Category A: Top 70% of revenue (
porcentaje_acumulado ≤ 0.7) - Category B: Next 20% of revenue (
0.7 < porcentaje_acumulado ≤ 0.9) - Category C: Remaining 10% (
porcentaje_acumulado > 0.9)
Usage Example
Source Code
decisiones
Module:
decisiones.py | Purpose: Evaluate stock risk and generate replenishment recommendationsevaluar_riesgo_y_reposicion()
Analyzes current stock levels and calculates recommended replenishment quantities.DataFrame with inventory dataRequired columns:
stock_actual: Current stock quantitystock_minimo: Minimum acceptable stock levelventas_mensuales: Monthly sales volume
DataFrame with two new columns:
estado_stock: Risk state (“CRITICO”, “RIESGO”, or “OK”)reponer_cantidad: Recommended replenishment quantity (0 or positive integer)
Risk States
- CRÍTICO
- RIESGO
- OK
Condition:
stock_actual ≤ stock_minimoImmediate replenishment required to prevent stockoutsReplenishment Formula
Usage Example
Source Code
reportes
Module:
reportes.py | Purpose: Generate formatted Excel reportsgenerar_reporte_excel()
Creates a multi-sheet Excel workbook with full inventory, critical items, and at-risk items.Processed DataFrame containing all analysis columnsExpected columns:
estado_stock: Used to filter critical and at-risk items- All original and computed columns (ABC category, replenishment qty, etc.)
Output path for the Excel fileExample:
"output/reporte_inventario.xlsx"No return value. File is written to disk.
Excel Workbook Structure
Sheet 1: Inventario_Completo
Sheet 1: Inventario_Completo
Contains all products with all computed columns
Sheet 2: Productos_Criticos
Sheet 2: Productos_Criticos
Filtered view of products with
estado_stock == "CRITICO"Sheet 3: Productos_En_Riesgo
Sheet 3: Productos_En_Riesgo
Filtered view of products with
estado_stock == "RIESGO"Formatting Features
- Auto-adjusted column widths based on content
- Centered cell alignment (horizontal and vertical)
- Professional appearance for stakeholder review
Usage Example
Source Code
reportes_graficos
Module:
reportes_graficos.py | Purpose: Generate visualization chartsgenerar_graficos()
Creates PNG charts for stock status and ABC classification distribution.Processed DataFrame with analysis resultsRequired columns:
estado_stock: For stock status chartcategoria_abc: For ABC classification chart
Output directory for PNG files (created if it doesn’t exist)Example:
"output/graficos"No return value. PNG files are written to disk:
estado_inventario.png: Bar chart of stock statesclasificacion_abc.png: Pie chart of ABC categories
Generated Charts
- Stock Status (Bar Chart)
- ABC Classification (Pie Chart)
File:
estado_inventario.pngType: Bar chartData: Count of products in each state (CRÍTICO, RIESGO, OK)Axes:- X: Stock state
- Y: Number of products
Usage Example
Source Code
emailer
Module:
emailer.py | Purpose: Send reports via email using SMTPenviar_reporte()
Sends the generated Excel report via email with automatic attachment handling.Sender’s email address (Gmail account)Example:
"[email protected]"Gmail app password (not regular account password)
Recipient’s email addressExample:
"[email protected]"Path to the Excel file to attachExample:
"output/reporte_inventario.xlsx"No return value. Email is sent via SMTP.
Raised if authentication fails or email cannot be sent
Email Structure
- Subject:
📦 Reporte Automático de Inventario - Body: Plain text notification message
- Attachment: Excel file with original filename
SMTP Configuration
- Server:
smtp.gmail.com - Port:
465(SSL) - Protocol: SMTP_SSL
Usage Example
Source Code
Complete Pipeline Example
Here’s how all modules work together inmain.py: