Files
project-managment/apps/finance/models.py
T

66 lines
2.3 KiB
Python

from django.db import models
class Invoice(models.Model):
class Status(models.TextChoices):
PENDING = "pending"
PAID = "paid"
OVERDUE = "overdue"
project = models.ForeignKey("projects.Project", on_delete=models.CASCADE, related_name="invoices")
client = models.ForeignKey("accounts.CustomUser", on_delete=models.CASCADE, related_name="invoices")
amount = models.DecimalField(max_digits=10, decimal_places=2)
due_date = models.DateField()
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-created_at"]
def __str__(self):
return f"Invoice #{self.id} - {self.amount}"
class Payment(models.Model):
invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, related_name="payments")
paid_at = models.DateTimeField()
method = models.CharField(max_length=100)
amount = models.DecimalField(max_digits=10, decimal_places=2)
reference = models.CharField(max_length=255, blank=True)
class Meta:
ordering = ["-paid_at"]
def __str__(self):
return f"Payment {self.method} for Invoice #{self.invoice_id}"
class Expense(models.Model):
project = models.ForeignKey("projects.Project", on_delete=models.CASCADE, related_name="expenses")
raised_by = models.ForeignKey("accounts.CustomUser", on_delete=models.CASCADE, related_name="expenses")
amount = models.DecimalField(max_digits=10, decimal_places=2)
category = models.CharField(max_length=100)
description = models.TextField(blank=True)
date = models.DateField(auto_now_add=True)
class Meta:
ordering = ["-date"]
def __str__(self):
return f"{self.category} - {self.amount}"
class TeamPayment(models.Model):
member = models.ForeignKey("accounts.CustomUser", on_delete=models.CASCADE, related_name="team_payments")
period = models.DateField()
amount = models.DecimalField(max_digits=10, decimal_places=2)
paid_at = models.DateTimeField(null=True, blank=True)
notes = models.TextField(blank=True)
class Meta:
ordering = ["-period"]
def __str__(self):
return f"{self.member} - {self.period} - {self.amount}"