Saltar a contenido

Apéndice I — Rollback de PROD a CERT

Si en las primeras 72h se detecta problema sistémico:

systemctl stop tienda tienda-daphne tienda-celery tienda-celerybeat
sed -i 's/DGII_AMBIENTE_DEFAULT=PROD/DGII_AMBIENTE_DEFAULT=CERT/' /opt/tienda/.env

sudo -u tienda bash -c 'cd /opt/tienda && set -a && . .env && set +a && \
    .venv/bin/python manage.py shell -c "
from accounting.models import ECFSequence
ECFSequence.objects.filter(ambiente=\"CERT\").update(activo=True)
ECFSequence.objects.filter(ambiente=\"PROD\").update(activo=False)
"'

# Marcar facturas PROD ERROR/RECHAZADO como REQUIERE_REVISION
sudo -u tienda bash -c 'cd /opt/tienda && set -a && . .env && set +a && \
    .venv/bin/python manage.py shell -c "
from accounting.models import SaleInvoice
from django.utils import timezone
from datetime import timedelta
SaleInvoice.objects.filter(
    ecf_ambiente=\"PROD\",
    ecf_estado__in=[\"ERROR\", \"RECHAZADO\"],
    ecf_fecha_envio__gte=timezone.now()-timedelta(days=3),
).update(ecf_estado=\"REQUIERE_REVISION\")
"'

systemctl start tienda tienda-daphne tienda-celery tienda-celerybeat

Importante: facturas PROD aceptadas son legalmente válidas, no se pueden borrar sin emitir nota de crédito (E34).