avancé dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import math
|
||||
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.db import models
|
||||
@@ -7,18 +8,47 @@ from django.utils import timezone
|
||||
from django.contrib import admin
|
||||
|
||||
class Collabs_hour(models.Model):
|
||||
|
||||
BASES_CHOICES = [
|
||||
('1', 'Monthey'),
|
||||
('2', 'Uvrier'),
|
||||
]
|
||||
|
||||
userName = models.CharField("Auteur", max_length=100)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Collaborateur", on_delete=models.DO_NOTHING, default=0)
|
||||
nHour = models.PositiveIntegerField("Heures", default=0, validators=[MinValueValidator(0), MaxValueValidator(23)])
|
||||
nMinutes = models.PositiveIntegerField("Minutes", default=0, validators=[MinValueValidator(0), MaxValueValidator(60)])
|
||||
sRemarques = models.TextField("Remarques")
|
||||
bNoticed = models.BooleanField("Pris en compte", blank=True)
|
||||
sRemarques = models.TextField("Remarques", blank=True)
|
||||
bNoticed = models.BooleanField("Vérifiée", blank=True, default=False)
|
||||
dtDate = models.DateField('Date', blank=False)
|
||||
sBases = models.CharField('Employé de la base de', max_length=1, choices=BASES_CHOICES,default=1)
|
||||
dtUpdate = models.DateTimeField('Date de modification', auto_now=True)
|
||||
dtCreated = models.DateTimeField('Date de création', auto_now_add=True)
|
||||
|
||||
|
||||
|
||||
@admin.display( description='Total du mois')
|
||||
def get_total_hour_by_user(self):
|
||||
objs = Collabs_hour.objects.filter(user=self.user,dtCreated__year=self.dtCreated.year, dtCreated__month=self.dtCreated.month)
|
||||
|
||||
total = 0.0
|
||||
|
||||
for object in objs:
|
||||
total += object.nHour + object.nMinutes/60
|
||||
print(f"hour = {object.nHour} minutes = {object.nMinutes} = {object.nMinutes/60}")
|
||||
|
||||
|
||||
print(total)
|
||||
|
||||
return str(int(math.floor(total))) + ':' + str(int((total%(math.floor(total)))*60)) + f" ({total})"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "heure suplémentaire"
|
||||
verbose_name_plural = "heures suplémentaires"
|
||||
permissions = (
|
||||
("can_notice", "Peut noter comme traitée"),
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user