hackens-orga/budget/models.py
2024-06-09 19:49:25 +02:00

39 lines
1.2 KiB
Python

from datetime import date
from agent.models import Agent
from django.db import models
class BudgetLine(models.Model):
title = models.CharField(max_length=255, verbose_name="Libellé")
amount = models.DecimalField(
max_digits=12, decimal_places=2, verbose_name="Montant (dépense en négatif)"
)
author = models.ForeignKey(Agent, on_delete=models.PROTECT, verbose_name="Auteur")
date = models.DateField(default=date.today, verbose_name="Date")
group = models.ForeignKey(
"BudgetGroup", on_delete=models.CASCADE, verbose_name="Budget"
)
comment = models.TextField(blank=True, verbose_name="Commentaire")
def __str__(self):
return f"{self.title}"
def __repr__(self):
return f"BudgetLine_{self.title}_{self.amount}"
class BudgetGroup(models.Model):
name = models.CharField(max_length=255, verbose_name="Intitulé")
description = models.TextField(blank=True, verbose_name="Description")
def get_all_lines(self):
lines = self.budgetline_set.all().order_by("date")
s = 0
return [(line, s := s + line.amount) for line in lines]
def __str__(self):
return f"{self.name}"
def __repr__(self):
return f"BudgetGroup_{self.name}"