2023-01-16 18:50:12 +01:00
|
|
|
from datetime import date
|
|
|
|
|
2023-02-08 02:04:34 +01:00
|
|
|
from agent.models import Agent
|
2023-01-16 18:50:12 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class BudgetLine(models.Model):
|
|
|
|
amount = models.DecimalField(max_digits=12, decimal_places=2)
|
2023-02-08 02:04:34 +01:00
|
|
|
author = models.ForeignKey(Agent, on_delete=models.PROTECT)
|
2023-01-16 18:50:12 +01:00
|
|
|
comment = models.TextField(blank=True)
|
|
|
|
date = models.DateField(default=date.today)
|
|
|
|
facture = models.FileField(upload_to="factures/", null=True, blank=True)
|
|
|
|
group = models.ForeignKey("BudgetGroup", on_delete=models.CASCADE)
|
|
|
|
title = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-02-16 19:10:23 +01:00
|
|
|
return f"{self.title}"
|
|
|
|
|
|
|
|
def __repr__(self):
|
2023-01-16 18:50:12 +01:00
|
|
|
return f"BudgetLine_{self.title}_{self.amount}€"
|
|
|
|
|
|
|
|
|
|
|
|
class BudgetGroup(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
description = models.TextField(blank=True)
|
|
|
|
|
2023-02-08 03:30:11 +01:00
|
|
|
def get_total(self):
|
|
|
|
return sum(i.amount for i in self.budgetline_set.all())
|
|
|
|
|
2023-01-16 18:50:12 +01:00
|
|
|
def __str__(self):
|
2023-02-16 19:10:23 +01:00
|
|
|
return f"{self.name}"
|
|
|
|
|
|
|
|
def __repr__(self):
|
2023-01-16 18:50:12 +01:00
|
|
|
return f"BudgetGroup_{self.name}"
|