aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ctrack/register/models.py10
-rw-r--r--ctrack/register/tests/test_event_models.py36
2 files changed, 42 insertions, 4 deletions
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index 06c0959..0358b00 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -5,6 +5,7 @@ from typing import Optional, Dict
from django.contrib.auth import get_user_model
from django.db import models
+from django.db.models import Q
from ctrack.caf.models import CAF
from ctrack.organisations.models import Person
@@ -16,7 +17,6 @@ class EventType(Enum):
PHONE_CALL = auto()
VIDEO_CALL = auto()
CAF_INITIAL_CAF_RECEIVED = auto()
- CAF_INITIAL_CAF_EMAILED_ROSA = auto()
CAF_FEEDBACK_EMAILED_OES = auto()
CAF_RECEIVED = auto()
CAF_EMAILED_ROSA = auto()
@@ -132,9 +132,13 @@ class CAFSingleDateEvent(EventBase, CAFMixin, SingleDateMixin):
class Meta:
constraints = [
+ # We can't do multiple CAFSingleDateEvents in a single day unless
+ # the type is declared with the Q expression.
models.UniqueConstraint(
- fields=["date", "type_descriptor"], name="unique_caf_for_date"
- )
+ fields=["date", "type_descriptor"],
+ condition=~Q(type_descriptor="CAF_EMAILED_ROSA"),
+ name="unique_caf_for_date",
+ ),
]
diff --git a/ctrack/register/tests/test_event_models.py b/ctrack/register/tests/test_event_models.py
index 132f076..4d72d22 100644
--- a/ctrack/register/tests/test_event_models.py
+++ b/ctrack/register/tests/test_event_models.py
@@ -46,12 +46,46 @@ def test_cannot_add_two_caf_initial_caf_received_events_on_same_date(user, caf):
)
+def test_caf_initial_caf_emailed_rosa(user, caf):
+ now = datetime.datetime.now()
+ e = CAFSingleDateEvent.objects.create(
+ type_descriptor="CAF_EMAILED_ROSA",
+ related_caf=caf,
+ short_description="CAF sent to Rosa for X Company",
+ date="2020-10-10",
+ comments="Nice comments for this event",
+ user=user,
+ )
+ assert e.created_date.day == now.day
+
+
+def test_can_email_two_caf_on_same_date(user, caf):
+ now = datetime.datetime.now()
+ e1 = CAFSingleDateEvent.objects.create(
+ type_descriptor="CAF_EMAILED_ROSA",
+ related_caf=caf,
+ short_description="CAF sent to Rosa for X Company",
+ date="2020-10-10",
+ comments="Nice comments for this event",
+ user=user,
+ )
+ e2 = CAFSingleDateEvent.objects.create(
+ type_descriptor="CAF_INITIAL_CAF_EMAILED_ROSA",
+ related_caf=caf,
+ short_description="CAF sent to Rosa for X Company",
+ date="2020-10-10",
+ comments="Nice comments for this event",
+ user=user,
+ )
+ assert e1.created_date.day == now.day
+ assert e2.created_date.day == now.day
+
+
def test_event_type_enum():
assert EventType.MEETING.name == "MEETING"
assert EventType.PHONE_CALL.name == "PHONE_CALL"
assert EventType.VIDEO_CALL.name == "VIDEO_CALL"
assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED"
- assert EventType.CAF_INITIAL_CAF_EMAILED_ROSA.name == "CAF_INITIAL_CAF_EMAILED_ROSA"
assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES"
assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED"
assert EventType.CAF_EMAILED_ROSA.name == "CAF_EMAILED_ROSA"