Files
erp-efintel-2026-portainer/seed_projects.py
T

59 lines
2.0 KiB
Python

import os
import django
import sys
# Set up Django environment
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from expenses.models import Project
def run_seed():
print("Clearing existing projects to ensure clean portfolio seeding...")
# This might cascade to expenses, which is expected for seeding a clean MVP/dev environment
Project.objects.all().delete()
print("Seeding Portfolios and Projects...")
# Portfolio definitions: name and number of projects
portfolio_def = {
"Portafolio 1": 5,
"Portafolio 2": 4,
"Portafolio 3": 3,
"Portafolio 4": 1,
"Portafolio 5": 1,
"Portafolio 6": 1,
"Portafolio 7": 2,
}
for index, (port_name, num_projects) in enumerate(portfolio_def.items(), 1):
port_code = f"PORT-{index:03d}"
# Create portfolio (parent)
portfolio = Project.objects.create(
code=port_code,
name=port_name,
description=f"Portafolio principal para agrupar {num_projects} proyectos contables.",
assigned_budget_clp=50000000.00, # 50M base portfolio budget
parent=None
)
print(f"Created Portfolio: {portfolio.code} - {portfolio.name}")
# Create subprojects
for sub_idx in range(1, num_projects + 1):
sub_code = f"PRY-{index}{sub_idx:02d}"
subproject = Project.objects.create(
code=sub_code,
name=f"Proyecto {sub_idx} ({port_name})",
description=f"Subproyecto contable imputable de {port_name}.",
assigned_budget_clp=10000000.00, # 10M base subproject budget
parent=portfolio
)
print(f" Created Project: {subproject.code} - {subproject.name}")
print("✅ Portfolios and Projects seeding completed successfully.")
if __name__ == "__main__":
run_seed()