from django.db import models
from django.db.models import Sum

from Index.models import Parroquia


# Create your models here.
class Informe(models.Model):
    fecha=models.DateField(null=True,blank=True)
    parroquia=models.ForeignKey(Parroquia, on_delete=models.CASCADE)
    sector=models.CharField(max_length=120)
    ubicacion=models.CharField(max_length=120)
    observacion=models.TextField(null=True,blank=True)
    total=models.DecimalField(decimal_places=2, max_digits=9, default=0)

    def __str__(self):
        return str(self.fecha)

class FotosInforme(models.Model):
    informe=models.ForeignKey(Informe,on_delete=models.CASCADE)
    foto=models.ImageField(upload_to='fotos',null=True,blank=True)
    estado=models.BooleanField(default=False)

    def croquis(self):
        if self.estado:
            return "No"
        else:
            return "Si"

class Seniales(models.Model):
    nombre=models.CharField(max_length=60)
    dimension=models.DecimalField(max_digits=9, decimal_places=2, default=0)
    color=models.CharField(max_length=60, default="Blanco")

    def __str__(self):
        return self.nombre

class InformeDetalle(models.Model):
    fecha=models.DateField(null=True,blank=True)
    informe=models.ForeignKey(Informe,on_delete=models.CASCADE,null=True, blank=True)
    detalle=models.ForeignKey(Seniales, on_delete=models.CASCADE,null=True,blank=True)
    color=models.CharField(max_length=60,null=True,blank=True)
    ancho=models.DecimalField(max_digits=9,decimal_places=2, default=0)
    longitud=models.DecimalField(max_digits=9,decimal_places=2, default=0)
    cantidad=models.DecimalField(max_digits=9,decimal_places=2, default=0)
    total=models.DecimalField(max_digits=9,decimal_places=2, default=0)

    def save(
        self, force_insert=False, force_update=False, using=None, update_fields=None
    ):
        self.color=self.detalle.color
        self.fecha=self.informe.fecha

        super(InformeDetalle,self).save()


