Files
erp-efintel-2026-portainer/scripts/seed_specialties.py
T

64 lines
2.3 KiB
Python

import os
import django
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from django.contrib.auth.models import User
from expenses.models import Project, Category, UserProfile
def seed():
print("Seeding project categories and user specialties...")
# Load categories
cat_1201 = Category.objects.filter(code="1201").first()
cat_1202 = Category.objects.filter(code="1202").first()
cat_1203 = Category.objects.filter(code="1203").first()
cat_1204 = Category.objects.filter(code="1204").first()
cat_1205 = Category.objects.filter(code="1205").first()
# Link categories to some projects
projs = Project.objects.filter(parent__isnull=False)
if projs.exists():
# Set category on a few subprojects
mapping = {
"PRY-101": (cat_1201, "ACTIVO"),
"PRY-102": (cat_1202, "PAUSADA"),
"PRY-103": (cat_1203, "ACTIVO"),
"PRY-104": (cat_1204, "TERMINADO"),
"PRY-201": (cat_1201, "ACTIVO"),
"PRY-202": (cat_1202, "ACTIVO"),
"PRY-301": (cat_1205, "PAUSADA"),
}
for code, (cat, status) in mapping.items():
proj = Project.objects.filter(code=code).first()
if proj and cat:
proj.category = cat
proj.status = status
proj.save()
print(f"Set Project {proj.code} Category to {cat.code} and Status to {status}")
# Set specialties on users
miguel = User.objects.filter(username="miguel_contreras").first()
ginevra = User.objects.filter(username="ginevra_ortega").first()
admin = User.objects.filter(username="admin").first()
if miguel and hasattr(miguel, 'profile'):
miguel.profile.specialties.set([cat_1201, cat_1202])
print(f"Set miguel_contreras specialties to 1201, 1202")
if ginevra and hasattr(ginevra, 'profile'):
ginevra.profile.specialties.set([cat_1202, cat_1203, cat_1204])
print(f"Set ginevra_ortega specialties to 1202, 1203, 1204")
if admin and hasattr(admin, 'profile'):
admin.profile.specialties.set([cat_1205])
print(f"Set admin specialties to 1205")
print("✅ Project categories and user specialties seeding completed.")
if __name__ == "__main__":
seed()