Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-approved budgets #3852

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions app/grandchallenge/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,56 @@
class ChallengeSet(models.QuerySet):
def with_available_compute(self):
return self.annotate(
approved_compute_costs_euro_millicents=(
complimentary_compute_costs=(
Sum(
"invoices__compute_costs_euros",
filter=Q(
invoices__payment_status__in=[
PaymentStatusChoices.COMPLIMENTARY,
PaymentStatusChoices.PAID,
]
invoices__payment_status=PaymentStatusChoices.COMPLIMENTARY
),
output_field=models.PositiveBigIntegerField(),
default=0,
)
),
paid_compute_costs=(
Sum(
"invoices__compute_costs_euros",
filter=Q(
invoices__payment_status=PaymentStatusChoices.PAID
),
output_field=models.PositiveBigIntegerField(),
default=0,
)
),
preapproved_compute_costs_if_anything_paid=(
Case(
When(
paid_compute_costs__gt=0,
then=Sum(
"invoices__compute_costs_euros",
filter=Q(invoices__budget_preapproved=True)
& ~Q(
invoices__payment_status__in=[
PaymentStatusChoices.PAID,
PaymentStatusChoices.COMPLIMENTARY,
]
),
output_field=models.PositiveBigIntegerField(),
default=0,
),
),
default=0,
output_field=models.PositiveBigIntegerField(),
)
),
approved_compute_costs_euro_millicents=ExpressionWrapper(
(
F("complimentary_compute_costs")
+ F("paid_compute_costs")
+ F("preapproved_compute_costs_if_anything_paid")
)
* 1000
* 100
* 100,
output_field=models.PositiveBigIntegerField(),
),
available_compute_euro_millicents=ExpressionWrapper(
F("approved_compute_costs_euro_millicents")
Expand Down Expand Up @@ -1503,7 +1539,6 @@ class TaskResponsiblePartyChoices(models.TextChoices):

class OnboardingTaskQuerySet(models.QuerySet):
def with_overdue_status(self):

_now = now()
return self.annotate(
is_overdue=Case(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.19 on 2025-02-25 11:04

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("invoices", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="invoice",
name="budget_preapproved",
field=models.BooleanField(
default=False,
help_text="Preapproval will make the budget immediately available, regardless of the payment status, but only if there is another invoice in the paid state.",
),
),
migrations.AlterField(
model_name="invoice",
name="payment_status",
field=models.CharField(
choices=[
("INITIALIZED", "Initialized"),
("REQUESTED", "Invoice Requested"),
("ISSUED", "Issued"),
("COMPLIMENTARY", "Complimentary"),
("PAID", "Paid"),
],
default="INITIALIZED",
max_length=13,
),
),
]
7 changes: 7 additions & 0 deletions app/grandchallenge/invoices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class PaymentStatusChoices(models.TextChoices):
INITIALIZED = "INITIALIZED", "Initialized"
REQUESTED = "REQUESTED", "Invoice Requested"
ISSUED = "ISSUED", "Issued"
COMPLIMENTARY = "COMPLIMENTARY", "Complimentary"
PAID = "PAID", "Paid"
Expand Down Expand Up @@ -76,3 +77,9 @@ class Invoice(models.Model):
choices=PaymentStatusChoices.choices,
default=PaymentStatusChoices.INITIALIZED,
)
budget_preapproved = models.BooleanField(
default=False,
help_text="Preapproval will make the budget immediately available, "
"regardless of the payment status, but only if there is another "
"invoice in the paid state.",
)
Loading