|
|
@ -1,6 +1,6 @@ |
|
|
import json |
|
|
import json |
|
|
from django.core.management.base import BaseCommand |
|
|
from django.core.management.base import BaseCommand |
|
|
from repostajes.models import Repostaje |
|
|
|
|
|
|
|
|
from repostajes.models import Repostaje, Vehiculo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand): |
|
|
class Command(BaseCommand): |
|
|
@ -25,21 +25,25 @@ class Command(BaseCommand): |
|
|
|
|
|
|
|
|
repostajes_creados = 0 |
|
|
repostajes_creados = 0 |
|
|
for repostaje_data in datos: |
|
|
for repostaje_data in datos: |
|
|
repostaje, creado = Repostaje.objects.get_or_create( |
|
|
|
|
|
fecha=repostaje_data['fecha'], |
|
|
|
|
|
defaults={ |
|
|
|
|
|
'kms': repostaje_data['kms'], |
|
|
|
|
|
'litros': repostaje_data['litros'], |
|
|
|
|
|
'descuento': repostaje_data['descuento'], |
|
|
|
|
|
'importe': repostaje_data['importe'], |
|
|
|
|
|
'precioxlitro': repostaje_data['precioxlitro'], |
|
|
|
|
|
'kmsrecorridos': repostaje_data['kmsrecorridos'], |
|
|
|
|
|
'consumo': repostaje_data['consumo'], |
|
|
|
|
|
'vehiculo': repostaje_data['vehiculo'] |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
if creado: |
|
|
|
|
|
repostajes_creados += 1 |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
vehiculo = Vehiculo.objects.get(id=repostaje_data["vehiculo"]) |
|
|
|
|
|
|
|
|
|
|
|
creado = Repostaje.objects.create( |
|
|
|
|
|
vehiculo_id=vehiculo.id, |
|
|
|
|
|
fecha=repostaje_data['fecha'], |
|
|
|
|
|
kms=repostaje_data['kms'], |
|
|
|
|
|
litros=repostaje_data['litros'], |
|
|
|
|
|
descuento=repostaje_data['descuento'], |
|
|
|
|
|
importe=repostaje_data['importe'], |
|
|
|
|
|
precioxlitro=repostaje_data['precioxlitro'], |
|
|
|
|
|
kmsrecorridos=repostaje_data['kmsrecorridos'], |
|
|
|
|
|
consumo=repostaje_data['consumo'] |
|
|
|
|
|
) |
|
|
|
|
|
if creado: |
|
|
|
|
|
repostajes_creados += 1 |
|
|
|
|
|
|
|
|
|
|
|
except Vehiculo.DoesNotExist: |
|
|
|
|
|
self.stderr.write(self.style.ERROR(f"Vehiculo '{repostaje_data['vehiculo']}' no encontrado.")) |
|
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS(f'Se importaron {repostajes_creados} repostajes correctamente.')) |
|
|
self.stdout.write(self.style.SUCCESS(f'Se importaron {repostajes_creados} repostajes correctamente.')) |
|
|
|
|
|
|
|
|
|