コード例 #1
0
    def get_context_data(self, **kwargs):
        kwargs["referents"] = self.object.memberships.filter(
            membership_type=Membership.MEMBERSHIP_TYPE_REFERENT).order_by(
                "created")
        kwargs["managers"] = self.object.memberships.filter(
            membership_type=Membership.MEMBERSHIP_TYPE_MANAGER).order_by(
                "created")
        kwargs["members"] = self.object.memberships.all().order_by("created")
        kwargs["has_promo_code"] = self.object.tags.filter(
            label=settings.PROMO_CODE_TAG).exists()
        if kwargs["has_promo_code"]:
            kwargs["group_promo_codes"] = get_promo_codes(self.object)

        if is_promo_code_delayed():
            kwargs["promo_code_delay"] = next_promo_code_date()

        kwargs["certifiable"] = (
            self.object.type in settings.CERTIFIABLE_GROUP_TYPES
            or self.object.subtypes.filter(
                label__in=settings.CERTIFIABLE_GROUP_SUBTYPES).exists())
        kwargs["satisfy_requirements"] = len(kwargs["referents"]) > 1
        kwargs["allocation_balance"] = get_balance(self.object)
        kwargs["spending_requests"] = SpendingRequest.objects.filter(
            group=self.object).exclude(status=SpendingRequest.STATUS_PAID)
        kwargs["is_pressero_enabled"] = is_pressero_enabled()

        kwargs["active"] = self.active_panel.get(self.request.POST.get("form"))

        forms = self.get_forms()
        for form_name, form in forms.items():
            kwargs.setdefault(form_name, form)

        return super().get_context_data(**kwargs, )
コード例 #2
0
    def get(self, request, *args, **kwargs):
        group = self.get_object()
        donation = get_balance(group)
        spending_requests = [{
            "id":
            spending_request.id,
            "title":
            spending_request.title,
            "status":
            spending_request.get_status_display(),
            "date":
            spending_request.spending_date,
            "link":
            front_url("manage_spending_request",
                      kwargs={"pk": spending_request.pk}),
        } for spending_request in (
            SpendingRequest.objects.filter(group=group).exclude(
                status=SpendingRequest.STATUS_PAID).order_by("-spending_date").
            only("id", "title", "status", "spending_date"))]

        return Response(
            status=status.HTTP_200_OK,
            data={
                "donation": donation,
                "spendingRequests": spending_requests
            },
        )
コード例 #3
0
def group_formatter(group):
    return format_html(
        '<a href="{group_link}">{group_name}</a> ({group_balance})<br><a href="mailto:{group_email}">{group_email}</a><br>{group_phone}',
        group_name=group.name,
        group_email=group.contact_email,
        group_phone=group.contact_phone,
        group_link=front_url("view_group", args=(group.id, )),
        group_balance=display_price(get_balance(group)),
    )
コード例 #4
0
    def validate_unique(self, exclude=None):
        try:
            super().validate_unique(exclude)
        except ValidationError as e:
            errors = e.message_dict
        else:
            errors = {}

        from agir.donations.allocations import get_balance

        if self.group and isinstance(self.amount, int) and self.amount < 0:
            balance = get_balance(self.group)

            if balance + self.amount < 0:

                errors.setdefault("amount", []).append(
                    ValidationError(
                        f"La balance d'un groupe ne peut pas devenir négative (actuellement : {display_price(balance)})",
                        code="negative_balance",
                    ))

        if errors:
            raise ValidationError(errors)
コード例 #5
0
def summary(spending_request):
    """Renvoie un résumé de la demande de dépense pour l'affichage sur la page de gestion

    :param spending_request: la demande de dépense à résumer
    :return: un itérateur vers les différents champs constituant le résumé
    """

    other_display_fields = [
        "category_precisions",
        "explanation",
        "spending_date",
        "provider",
        "iban",
        "payer_name",
    ]

    yield {
        "label": "Identifiant de la demande",
        "value": str(spending_request.pk)[:6]
    }
    yield {
        "label": get_spending_request_field_label("title"),
        "value": spending_request.title,
    }

    status = spending_request.get_status_display()
    if spending_request.status == SpendingRequest.STATUS_DRAFT and can_be_sent(
            spending_request):
        status = _(
            "Dès que votre brouillon est complet, vous pouvez le confirmer pour validation par l'équipe de suivi."
        )

    if spending_request.status in SpendingRequest.STATUS_NEED_ACTION:
        status = format_html("<strong>{}</strong>", status)
    yield {
        "label": get_spending_request_field_label("status"),
        "value": status
    }

    balance = get_balance(spending_request.group)

    amount_text = display_price(spending_request.amount)
    if spending_request.amount > balance:
        amount_text = format_html(
            "{}<br><strong style=\"color: #BB1111;\">L'allocation de votre groupe est pour l'instant insuffisante, votre"
            " demande ne pourra pas être validée</strong>",
            amount_text,
        )

    yield {
        "label": get_spending_request_field_label("amount"),
        "value": amount_text
    }
    yield {
        "label":
        get_spending_request_field_label("event"),
        "value":
        format_html(
            '<a href="{link}">{name}</a>',
            link=reverse("view_event",
                         kwargs={"pk": spending_request.event.id}),
            name=spending_request.event.name,
        ) if spending_request.event else _("Aucun"),
    }
    yield {
        "label": get_spending_request_field_label("category"),
        "value": spending_request.get_category_display(),
    }

    for f in other_display_fields:
        yield {
            "label": get_spending_request_field_label(f),
            "value": getattr(spending_request, f),
        }
コード例 #6
0
def are_funds_sufficient(spending_request):
    return spending_request.amount <= get_balance(spending_request.group)