Skip to content
Merged
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
8 changes: 8 additions & 0 deletions dashboard/framework/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def save(self, *args, **kwargs):
from projects.models import (
ProjectObjective,
ProjectObjectiveCondition,
Commitment
) # avoids circular import

super().save(*args, **kwargs)
Expand All @@ -178,6 +179,13 @@ def save(self, *args, **kwargs):
objective=projectobjective.objective,
condition=self,
)
for work_cycle in WorkCycle.objects.all():
Commitment.objects.get_or_create(
work_cycle=work_cycle,
project=projectobjective.project,
objective=projectobjective.objective,
level=self.level,
)

class Meta:
ordering = ["objective__name", "level__value"]
29 changes: 29 additions & 0 deletions dashboard/framework/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,32 @@ def test_new_objective_means_new_commitments(

assert project.commitment_set.count() == 2
assert work_cycle.commitment_set.count() == 2


@pytest.mark.django_db
def test_new_condition_with_new_level_backfills_commitment(
project, objective, condition, work_cycle
):
# A new condition at a new level should create a matching commitment
# for existing rows.

assert (
Commitment.objects.filter(
project=project, objective=objective, work_cycle=work_cycle
).count()
== 1
)

new_level = Level.objects.create(name="test_level_2", value=2)
Condition.objects.create(
name="test_condition_2", objective=objective, level=new_level
)

# Expected behaviour: creating a new condition/level backfills
# commitments.
assert Commitment.objects.filter(
project=project,
objective=objective,
work_cycle=work_cycle,
level=new_level,
).exists()
Loading