Se modifico comadno eliminar pedimentos duplicados
This commit is contained in:
@@ -9,14 +9,14 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
duplicados = (
|
duplicados = (
|
||||||
Pedimento.objects
|
Pedimento.objects
|
||||||
.values('pedimento_app')
|
.values('pedimento')
|
||||||
.annotate(total=Count('id'))
|
.annotate(total=Count('id'))
|
||||||
.filter(total__gt=1)
|
.filter(total__gt=1)
|
||||||
)
|
)
|
||||||
for dup in duplicados:
|
for dup in duplicados:
|
||||||
pedimentos = (
|
pedimentos = (
|
||||||
Pedimento.objects
|
Pedimento.objects
|
||||||
.filter(pedimento_app=dup['pedimento_app'])
|
.filter(pedimento=dup['pedimento'])
|
||||||
.annotate(
|
.annotate(
|
||||||
num_docs=Count('documents'),
|
num_docs=Count('documents'),
|
||||||
num_coves=Count('coves'),
|
num_coves=Count('coves'),
|
||||||
@@ -28,10 +28,10 @@ class Command(BaseCommand):
|
|||||||
# Mantener el primero, eliminar los demás
|
# Mantener el primero, eliminar los demás
|
||||||
to_delete = pedimentos[1:]
|
to_delete = pedimentos[1:]
|
||||||
for ped in to_delete:
|
for ped in to_delete:
|
||||||
self.stdout.write(f'Eliminando pedimento {ped.id} ({ped.pedimento_app})')
|
self.stdout.write(f'Eliminando pedimento {ped.id} ({ped.pedimento})')
|
||||||
Cove.objects.filter(pedimento=ped).delete()
|
Cove.objects.filter(pedimento=ped).delete()
|
||||||
EDocument.objects.filter(pedimento=ped).delete()
|
EDocument.objects.filter(pedimento=ped).delete()
|
||||||
Partida.objects.filter(pedimento=ped).delete()
|
Partida.objects.filter(pedimento=ped).delete()
|
||||||
Document.objects.filter(pedimento=ped).delete()
|
Document.objects.filter(pedimento=ped).delete()
|
||||||
ped.delete()
|
ped.delete()
|
||||||
self.stdout.write(self.style.SUCCESS('Eliminación de duplicados completada.'))
|
self.stdout.write(self.style.SUCCESS('Eliminación de duplicados completada.'))
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.3 on 2025-10-07 00:36
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('customs', '0015_partida_updated_at'),
|
||||||
|
('organization', '0002_remove_organizacion_membretado_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='pedimento',
|
||||||
|
unique_together={('organizacion', 'pedimento'), ('organizacion', 'pedimento_app')},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -60,6 +60,10 @@ class Pedimento(models.Model):
|
|||||||
verbose_name_plural = "Pedimentos"
|
verbose_name_plural = "Pedimentos"
|
||||||
db_table = 'pedimento'
|
db_table = 'pedimento'
|
||||||
ordering = ['pedimento']
|
ordering = ['pedimento']
|
||||||
|
unique_together = [
|
||||||
|
['organizacion', 'pedimento'],
|
||||||
|
['organizacion', 'pedimento_app']
|
||||||
|
]
|
||||||
|
|
||||||
class Partida(models.Model):
|
class Partida(models.Model):
|
||||||
pedimento = models.ForeignKey(Pedimento, on_delete=models.CASCADE, related_name='partidas', help_text="Pedimento asociado a la partida")
|
pedimento = models.ForeignKey(Pedimento, on_delete=models.CASCADE, related_name='partidas', help_text="Pedimento asociado a la partida")
|
||||||
|
|||||||
Reference in New Issue
Block a user