nexus-5/core/models/invoice.py
2026-01-26 11:09:40 -05:00

33 lines
1.4 KiB
Python

from django.db import models
from django_choices_field.fields import TextChoicesField
from core.models.base import BaseModel
from core.models.customer import Customer
from core.models.enums import InvoiceChoices, PaymentChoices
from core.models.project import Project
from core.models.revenue import Revenue
class Invoice(BaseModel):
"""Invoice records"""
date = models.DateField()
customer = models.ForeignKey(Customer, on_delete=models.PROTECT, related_name='invoices')
projects = models.ManyToManyField(Project, related_name='invoices', blank=True)
revenues = models.ManyToManyField(Revenue, related_name='invoices', blank=True)
status = TextChoicesField(choices_enum=InvoiceChoices, default=InvoiceChoices.DRAFT,
help_text="Current status of the invoice")
date_paid = models.DateField(blank=True, null=True)
payment_type = TextChoicesField(choices_enum=PaymentChoices, blank=True, null=True)
wave_invoice_id = models.CharField(max_length=255, blank=True, null=True,
help_text="Wave invoice ID")
class Meta:
ordering = ['-date']
indexes = [
models.Index(fields=['customer', 'date']),
]
verbose_name = "Invoice"
verbose_name_plural = "Invoices"
def __str__(self):
return f"Invoice for {self.customer.name} on {self.date}"