Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Factura(BaseModel):
- empresa = models.ForeignKey(Empresa)
- codigo = models.CharField(max_length=50)
- fecha = models.DateField()
- cliente = models.ForeignKey(Cliente)
- total_iva = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- base = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- total = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- fecha_pagado = models.DateField(blank=True, null=True)
- def calculate(self):
- sum_total_iva = 0
- sum_base = 0
- sum_total = 0
- for factura_item in self.facturaitem_set.all():
- factura_item.calculate()
- sum_total_iva += factura_item.total_iva
- sum_base += factura_item.base
- sum_total += factura_item.total
- factura_item.save()
- self.total_iva = sum_total_iva
- self.base = sum_base
- self.total = sum_total
- def __unicode__(self):
- return "[" + str(self.id) + "][" + str(self.fecha) + "] " + self.cliente.name
- class FacturaItem(BaseModel):
- factura = models.ForeignKey(Factura)
- producto = models.ForeignKey(Producto)
- precio = models.DecimalField(max_digits=10, decimal_places=2)
- cantidad = models.DecimalField(max_digits=10, decimal_places=0)
- tipo_iva = models.DecimalField(max_digits=5, decimal_places=2, default=0)
- total_iva = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- base = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- total = models.DecimalField(max_digits=10, decimal_places=2, default=0)
- def get_absolute_url(self):
- return None
- def calculate(self):
- if self.tipo_iva is None or self.tipo_iva == 0:
- self.tipo_iva = self.producto.iva.tipo
- self.base = (self.precio * self.cantidad)
- self.total_iva = (self.base * self.tipo_iva / Decimal(100.0))
- self.total = self.base + self.total_iva
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement