Esempio n. 1
0
def generate_receipts_xls(worksheet, request):
    qs = treso_models.FactureRecue.objects
    qs = list(get_request_semester(qs, request).order_by('id'))
    for n, val in enumerate([
            "Référence", "Entreprise", "Date", "Date de paiement", "Prix TTC",
            "TVA", "Etat", "Personne à rembourser", "Date de remboursement",
            "Nom de la perm", "Date de la perm", "Période de la perm",
            "Responsable de la perm"
    ]):
        worksheet.write(0, n, val)
    for num, facture in enumerate(qs):
        serializer = FactureRecueExtendedSerializer(facture)
        for n, val in enumerate([
                facture.categorie.code +
                str(facture.id) if facture.categorie else facture.id,
                facture.nom_entreprise,
                str(facture.date or "--"),
                str(facture.date_paiement or "--"), facture.prix,
                facture.get_total_taxes(),
                facture.get_etat_display(), facture.personne_a_rembourser
                or "",
                str(facture.date_remboursement or "--")
        ]):
            worksheet.write(num + 1, n, val)
        if facture.perm:
            worksheet.write(num + 1, 9, facture.perm.perm.nom)
            worksheet.write(num + 1, 10, str(facture.perm.date))
            if facture.perm.creneau == "M":
                worksheet.write(num + 1, 11, "Matin")
            elif facture.perm.creneau == "D":
                worksheet.write(num + 1, 11, "Midi")
            else:
                worksheet.write(num + 1, 11, "Soir")
            worksheet.write(num + 1, 12,
                            (facture.perm.perm.nom_resp or "") + " - " +
                            (facture.perm.perm.mail_resp or "Pas d'email"))
        else:
            for i in range(9, 13):
                worksheet.write(num + 1, i, "--")
    return worksheet
Esempio n. 2
0
 def get_queryset(self):
     qs = perm_models.Astreinte.objects
     return get_request_semester(qs, self.request, "member__semestre__id")
Esempio n. 3
0
 def get_queryset(self):
     qs = perm_models.Creneau.objects
     return get_request_semester(qs, self.request, "perm__semestre__id")
Esempio n. 4
0
def get_perms_for_notation(request):
    """Obtenir les notation de toutes les perms du semestre entré (courant par défaut)"""
    qs = perm_models.Creneau.objects
    queryset = get_request_semester(qs, request, "perm__semestre__id")
    serializer = perm_serializers.CreneauSerializer(queryset, many=True)

    creneaux = serializer.data
    perms = dict()

    for creneau in creneaux : 

        perm_id = creneau["perm"]["id"]

        if perm_id not in perms : 

            perms[perm_id] = {}
            perms[perm_id] = creneau["perm"]
            perms[perm_id].pop("creneaux")
            perms[perm_id]["creneau"] = []
            perms[perm_id]["note_deco"] = 0
            perms[perm_id]["note_anim"] = 0
            perms[perm_id]["note_orga"] = 0
            perms[perm_id]["note_menu"] = 0
            perms[perm_id]["nb_note_deco"] = 0
            perms[perm_id]["nb_note_anim"] = 0
            perms[perm_id]["nb_note_orga"] = 0
            perms[perm_id]["nb_note_menu"] = 0
            perms[perm_id]["nb_astreintes"] = 0

        if not any(c for c in perms[perm_id]["creneau"] if c["id"] == creneau["id"]):

            creneau_data = creneau
            creneau_data.pop("perm")
            creneau_data.pop("state")
            creneau_data.pop("montantTTCMaxAutorise")
            creneau_data.pop('facturerecue_set')
            creneau_data["notation"] = []
            perms[perm_id]["creneau"].append(creneau_data)

    qs = perm_models.Astreinte.objects
    queryset = get_request_semester(qs, request, "member__semestre__id")
    serializer = perm_serializers.AstreinteSerializer(queryset, many=True)

    astreintes = serializer.data

    for astreinte in astreintes:
        perm_id = astreinte["creneau"]["perm"]["id"]

        if perm_id in perms:

            notation  = {
                "astreinte_type": astreinte["astreinte_type"],
                "note_deco": astreinte["note_deco"],
                "note_orga" : astreinte["note_orga"],
                "note_anim": astreinte["note_anim"],
                "note_menu": astreinte["note_menu"],
                "commentaire": astreinte["commentaire"]
            }

            if astreinte["note_deco"] > 0:
                perms[perm_id]["note_deco"] += astreinte["note_deco"]
                perms[perm_id]["nb_note_deco"] += 1
            if astreinte["note_anim"] > 0:
                perms[perm_id]["note_anim"] += astreinte["note_anim"]
                perms[perm_id]["nb_note_anim"] += 1
            if astreinte["note_orga"] > 0:
                perms[perm_id]["note_orga"] += astreinte["note_orga"]
                perms[perm_id]["nb_note_orga"] += 1
            if astreinte["note_menu"] > 0:
                perms[perm_id]["note_menu"] += astreinte["note_menu"]
                perms[perm_id]["nb_note_menu"] += 1
            perms[perm_id]["nb_astreintes"] += 1

            for creneau in perms[perm_id]["creneau"]:
                if creneau["id"] == astreinte["creneau"]["id"]:
                    creneau["notation"].append(notation)
                    break

    keys = perms.keys()
    for key in keys :

        # Obtenir la moyenne générale
        mean_note = 0
        mean_keys = 0

        if perms[key]["nb_note_deco"] > 0 :
            perms[key]["note_deco"] = round(perms[key]["note_deco"] / perms[key]["nb_note_deco"],2)
            mean_note += perms[key]["note_deco"]
            mean_keys += 1
        if perms[key]["nb_note_menu"] > 0 :
            perms[key]["note_menu"] = round(perms[key]["note_menu"] / perms[key]["nb_note_menu"],2)
            mean_note += perms[key]["note_menu"]
            mean_keys += 1
        if perms[key]["nb_note_orga"] > 0 :
            perms[key]["note_orga"] = round(perms[key]["note_orga"] / perms[key]["nb_note_orga"],2)
            mean_note += perms[key]["note_orga"]
            mean_keys += 1
        if perms[key]["nb_note_anim"] > 0 :
            perms[key]["note_anim"] = round(perms[key]["note_anim"] / perms[key]["nb_note_anim"],2)
            mean_note += perms[key]["note_anim"]
            mean_keys += 1

        if mean_keys > 0:
            mean_note = round(mean_note / mean_keys,2)
        perms[key]["mean_note"] = mean_note


    return JsonResponse({'perms': list(perms.values())})
Esempio n. 5
0
 def get_queryset(self):
     qs = perm_models.Perm.objects
     return get_request_semester(qs, self.request)
Esempio n. 6
0
 def get_queryset(self):
     qs = treso_models.FactureEmise.objects
     return get_request_semester(qs, self.request)
Esempio n. 7
0
 def get_queryset(self):
     # Tri par semestre
     qs = core_models.Member.objects
     return get_request_semester(qs, self.request)