agendas: split name into first name and last name for shared custody (#64423)

This commit is contained in:
Valentin Deniaud 2022-04-25 16:56:44 +02:00
parent f70aa2063a
commit 513980d5b1
12 changed files with 147 additions and 103 deletions

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.24 on 2022-05-02 09:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agendas', '0124_check_type_disabled'),
]
operations = [
migrations.RenameField(
model_name='person',
old_name='name',
new_name='first_name',
),
migrations.AddField(
model_name='person',
name='last_name',
field=models.CharField(default='', max_length=250),
preserve_default=False,
),
]

View File

@ -3167,10 +3167,11 @@ class Subscription(models.Model):
class Person(models.Model):
user_external_id = models.CharField(max_length=250, unique=True)
name = models.CharField(max_length=250)
first_name = models.CharField(max_length=250)
last_name = models.CharField(max_length=250)
def __str__(self):
return self.name
return '%s %s' % (self.first_name, self.last_name)
@dataclasses.dataclass(frozen=True)
@ -3181,9 +3182,9 @@ class SharedCustodySlot:
def __str__(self):
if self.label:
return '%s (%s)' % (self.guardian.name, self.label)
return '%s (%s)' % (self.guardian, self.label)
else:
return self.guardian.name
return str(self.guardian)
class SharedCustodyAgenda(models.Model):
@ -3198,8 +3199,8 @@ class SharedCustodyAgenda(models.Model):
@property
def label(self):
return _('Custody agenda of %(first_guardian)s and %(second_guardian)s') % {
'first_guardian': self.first_guardian.name,
'second_guardian': self.second_guardian.name,
'first_guardian': self.first_guardian,
'second_guardian': self.second_guardian,
}
def get_absolute_url(self):
@ -3470,4 +3471,4 @@ class SharedCustodyPeriod(models.Model):
date_format(self.date_start, 'SHORT_DATE_FORMAT'),
date_format(self.date_end, 'SHORT_DATE_FORMAT'),
)
return '%s, %s' % (self.guardian.name, exc_repr)
return '%s, %s' % (self.guardian, exc_repr)

View File

@ -489,12 +489,15 @@ class SubscriptionSerializer(serializers.ModelSerializer):
class SharedCustodyAgendaSerializer(serializers.Serializer):
first_guardian_name = serializers.CharField(max_length=250)
first_guardian_first_name = serializers.CharField(max_length=250)
first_guardian_last_name = serializers.CharField(max_length=250)
first_guardian_id = serializers.CharField(max_length=250)
second_guardian_name = serializers.CharField(max_length=250)
second_guardian_first_name = serializers.CharField(max_length=250)
second_guardian_last_name = serializers.CharField(max_length=250)
second_guardian_id = serializers.CharField(max_length=250)
class SharedCustodyChildSerializer(serializers.Serializer):
name = serializers.CharField(max_length=250)
first_name = serializers.CharField(max_length=250)
last_name = serializers.CharField(max_length=250)
user_external_id = serializers.CharField(max_length=250)

View File

@ -2778,11 +2778,17 @@ class SharedCustodyAgendas(APIView):
with transaction.atomic():
first_guardian, dummy = Person.objects.get_or_create(
user_external_id=data['first_guardian_id'],
defaults={'name': data['first_guardian_name']},
defaults={
'first_name': data['first_guardian_first_name'],
'last_name': data['first_guardian_last_name'],
},
)
second_guardian, dummy = Person.objects.get_or_create(
user_external_id=data['second_guardian_id'],
defaults={'name': data['second_guardian_name']},
defaults={
'first_name': data['second_guardian_first_name'],
'last_name': data['second_guardian_last_name'],
},
)
agenda = SharedCustodyAgenda.objects.create(
@ -2814,7 +2820,7 @@ class SharedCustodyAgendaAddChild(APIView):
with transaction.atomic():
child, dummy = Person.objects.get_or_create(
user_external_id=data['user_external_id'],
defaults={'name': data['name']},
defaults={'first_name': data['first_name'], 'last_name': data['last_name']},
)
if child.agendas.exists():
raise APIError(N_('This child already has one custody agenda.'))

View File

@ -31,7 +31,7 @@
{% for rule in agenda.rules.all %}
<li><a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-edit-rule' pk=agenda.pk rule_pk=rule.pk %}">
<span class="rule-info">
{{ rule.guardian.name }}, {{ rule.label }}
{{ rule.guardian }}, {{ rule.label }}
</span>
</a>
<a rel="popup" class="delete" href="{% url 'chrono-manager-shared-custody-agenda-delete-rule' pk=agenda.pk rule_pk=rule.pk %}?next=settings">{% trans "remove" %}</a>
@ -57,7 +57,7 @@
{% for rule in agenda.holiday_rules.all %}
<li><a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-edit-holiday-rule' pk=agenda.pk rule_pk=rule.pk %}">
<span class="rule-info">
{{ rule.guardian.name }}, {{ rule.label }}
{{ rule.guardian }}, {{ rule.label }}
</span>
</a>
<a rel="popup" class="delete" href="{% url 'chrono-manager-shared-custody-agenda-delete-holiday-rule' pk=agenda.pk rule_pk=rule.pk %}?next=settings">{% trans "remove" %}</a>

View File

@ -403,9 +403,9 @@ def test_datetimes_multiple_agendas_queries(app):
assert len(resp.json['data']) == 30
assert len(ctx.captured_queries) == 2
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='xxx', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)
@ -698,9 +698,9 @@ def test_datetimes_multiple_agendas_shared_custody(app):
assert len(resp.json['data']) == 2
# add shared custody agenda
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)
@ -823,9 +823,9 @@ def test_datetimes_multiple_agendas_shared_custody_other_rules(app):
date_end=now() + datetime.timedelta(days=14),
)
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)
@ -912,9 +912,9 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
date_end=now() + datetime.timedelta(days=30),
)
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)
@ -1115,9 +1115,9 @@ def test_datetimes_multiple_agendas_shared_custody_holiday_rules(app):
date_end=now() + datetime.timedelta(days=14),
)
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)

View File

@ -142,9 +142,9 @@ def test_recurring_events_api_list_shared_custody(app):
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
# add shared custody agenda
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
custody_agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
custody_agenda.children.add(child)
@ -327,9 +327,9 @@ def test_recurring_events_api_list_multiple_agendas_queries(app):
assert len(resp.json['data']) == 40
assert len(ctx.captured_queries) == 3
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='xxx', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)

View File

@ -599,9 +599,9 @@ def test_api_events_fillslots_multiple_agendas_shared_custody(app, user):
date_end=now() + datetime.timedelta(days=14),
)
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)

View File

@ -1293,9 +1293,9 @@ def test_recurring_events_api_fillslots_multiple_agendas_queries(app, user):
assert resp.json['booking_count'] == 180
assert len(ctx.captured_queries) == 13
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='xxx', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)
@ -1327,9 +1327,9 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
)
event.create_all_recurrences()
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
child = Person.objects.create(user_external_id='child_id', name='James Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
agenda.children.add(child)

View File

@ -9,15 +9,17 @@ def test_add_shared_custody_agenda(app, user, settings):
app.authorization = ('Basic', ('john.doe', 'password'))
params = {
'first_guardian_name': 'John Doe',
'first_guardian_first_name': 'John',
'first_guardian_last_name': 'Doe',
'first_guardian_id': 'xxx',
'second_guardian_name': 'Jane Doe',
'second_guardian_first_name': 'Jane',
'second_guardian_last_name': 'Doe',
'second_guardian_id': 'yyy',
}
resp = app.post_json('/api/shared-custody/', params=params)
john = Person.objects.get(user_external_id='xxx', name='John Doe')
jane = Person.objects.get(user_external_id='yyy', name='Jane Doe')
john = Person.objects.get(user_external_id='xxx', first_name='John', last_name='Doe')
jane = Person.objects.get(user_external_id='yyy', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.get()
assert agenda.first_guardian == john
@ -29,9 +31,11 @@ def test_add_shared_custody_agenda(app, user, settings):
}
params = {
'first_guardian_name': 'John Doe',
'first_guardian_first_name': 'John',
'first_guardian_last_name': 'Doe',
'first_guardian_id': 'xxx',
'second_guardian_name': 'Other',
'second_guardian_first_name': 'Other',
'second_guardian_last_name': 'Other',
'second_guardian_id': 'zzz',
}
resp = app.post_json('/api/shared-custody/', params=params)
@ -40,17 +44,18 @@ def test_add_shared_custody_agenda(app, user, settings):
def test_shared_custody_agenda_add_child(app, user, settings):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app.authorization = ('Basic', ('john.doe', 'password'))
params = {
'name': 'James Doe',
'first_name': 'James',
'last_name': 'Doe',
'user_external_id': 'xxx',
}
resp = app.post_json('/api/shared-custody/%s/add-child/' % agenda.pk, params=params)
child = Person.objects.get(name='James Doe', user_external_id='xxx')
child = Person.objects.get(first_name='James', last_name='Doe', user_external_id='xxx')
assert resp.json['data']['child_id'] == child.pk
assert agenda.children.count() == 1
@ -65,18 +70,23 @@ def test_shared_custody_agenda_add_child(app, user, settings):
assert Person.objects.count() == 3
params = {
'name': 'Jack Doe',
'first_name': 'Jack',
'last_name': 'Doe',
'user_external_id': 'yyy',
}
resp = app.post_json('/api/shared-custody/%s/add-child/' % agenda.pk, params=params)
child = Person.objects.get(name='Jack Doe', user_external_id='yyy')
child = Person.objects.get(first_name='Jack', last_name='Doe', user_external_id='yyy')
assert resp.json['data']['child_id'] == child.pk
assert agenda.children.count() == 2
assert Person.objects.count() == 4
other_father = Person.objects.create(user_external_id='other_father_id', name='John Doe')
other_mother = Person.objects.create(user_external_id='other_mother_id', name='Jane Doe')
other_father = Person.objects.create(
user_external_id='other_father_id', first_name='John', last_name='Doe'
)
other_mother = Person.objects.create(
user_external_id='other_mother_id', first_name='Jane', last_name='Doe'
)
other_agenda = SharedCustodyAgenda.objects.create(
first_guardian=other_father, second_guardian=other_mother
)

View File

@ -25,8 +25,8 @@ with open('tests/data/holidays.ics') as f:
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_settings_rules(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app = login(app)
@ -74,8 +74,8 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_settings_periods(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app = login(app)
@ -115,8 +115,8 @@ def test_shared_custody_agenda_settings_periods(app, admin_user):
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_month_view(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
@ -171,8 +171,8 @@ def test_shared_custody_agenda_month_view(app, admin_user):
def test_shared_custody_agenda_month_view_queries(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[0, 1, 2], weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[3, 4, 5, 6], weeks='odd')
@ -207,8 +207,8 @@ def test_shared_custody_agenda_month_view_queries(app, admin_user):
def test_shared_custody_agenda_holiday_rules(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app = login(app)

View File

@ -2768,8 +2768,8 @@ def test_recurring_events_create_past_recurrences(freezer):
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday of 8th week
def test_shared_custody_agenda():
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
@ -2788,7 +2788,7 @@ def test_shared_custody_agenda():
date_end=datetime.date(year=2022, month=2, day=25),
)
slots = agenda.get_custody_slots(now().date(), now().date() + datetime.timedelta(days=5))
slots = [(x.date.strftime('%d/%m'), x.guardian.name) for x in slots]
slots = [(x.date.strftime('%d/%m'), str(x.guardian)) for x in slots]
assert slots == [
('22/02', 'John Doe'),
('23/02', 'Jane Doe'),
@ -2805,7 +2805,7 @@ def test_shared_custody_agenda():
date_end=datetime.date(year=2022, month=3, day=3),
)
slots = agenda.get_custody_slots(now().date(), now().date() + datetime.timedelta(days=5))
slots = [(x.date.strftime('%d/%m'), x.guardian.name) for x in slots]
slots = [(x.date.strftime('%d/%m'), str(x.guardian)) for x in slots]
assert slots == [
('22/02', 'John Doe'),
('23/02', 'Jane Doe'),
@ -2818,20 +2818,20 @@ def test_shared_custody_agenda():
slots = agenda.get_custody_slots(
datetime.date(year=2022, month=2, day=27), datetime.date(year=2022, month=3, day=1)
)
slots = [(x.date.strftime('%d/%m'), x.guardian.name) for x in slots]
slots = [(x.date.strftime('%d/%m'), str(x.guardian)) for x in slots]
assert slots == [('27/02', 'John Doe'), ('28/02', 'John Doe')]
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_different_periodicity():
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=[1, 2, 3], guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=[0, 4, 5, 6], guardian=mother)
slots = agenda.get_custody_slots(now().date(), now().date() + datetime.timedelta(days=14))
assert [(x.date.strftime('%A %d/%m'), x.guardian.name) for x in slots] == [
assert [(x.date.strftime('%A %d/%m'), str(x.guardian)) for x in slots] == [
('Tuesday 22/02', 'John Doe'),
('Wednesday 23/02', 'John Doe'),
('Thursday 24/02', 'John Doe'),
@ -2873,8 +2873,8 @@ def test_shared_custody_agenda_different_periodicity():
),
)
def test_shared_custody_agenda_is_complete(rules, complete):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
for i, rule in enumerate(rules):
@ -2903,8 +2903,8 @@ def test_shared_custody_agenda_is_complete(rules, complete):
),
)
def test_shared_custody_agenda_rule_overlaps(rules, days, weeks, overlaps):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
for i, rule in enumerate(rules):
@ -2917,8 +2917,8 @@ def test_shared_custody_agenda_rule_overlaps(rules, days, weeks, overlaps):
def test_shared_custody_agenda_holiday_rule_overlaps():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -2987,8 +2987,8 @@ def test_shared_custody_agenda_holiday_rule_overlaps():
),
)
def test_shared_custody_agenda_period_overlaps(periods, date_start, date_end, overlaps):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
for i, dates in enumerate(periods):
@ -3003,8 +3003,8 @@ def test_shared_custody_agenda_period_overlaps(periods, date_start, date_end, ov
def test_shared_custody_agenda_period_holiday_rule_no_overlaps():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3020,8 +3020,8 @@ def test_shared_custody_agenda_period_holiday_rule_no_overlaps():
def test_shared_custody_agenda_rule_label():
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
@ -3052,8 +3052,8 @@ def test_shared_custody_agenda_rule_label():
def test_shared_custody_agenda_holiday_rule_label():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3090,8 +3090,8 @@ def test_shared_custody_agenda_holiday_rule_label():
def test_shared_custody_agenda_period_label(freezer):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
period = SharedCustodyPeriod.objects.create(
@ -3110,8 +3110,8 @@ def test_shared_custody_agenda_period_label(freezer):
def test_shared_custody_agenda_holiday_rule_create_periods():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3213,8 +3213,8 @@ def test_shared_custody_agenda_holiday_rule_create_periods():
def test_shared_custody_agenda_holiday_rule_create_periods_christmas_holidays():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
christmas_holiday = TimePeriodExceptionGroup.objects.create(
@ -3273,8 +3273,8 @@ def test_shared_custody_agenda_holiday_rule_create_periods_christmas_holidays():
def test_shared_custody_agenda_holiday_rules_application():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
christmas_holiday = TimePeriodExceptionGroup.objects.create(
@ -3295,7 +3295,7 @@ def test_shared_custody_agenda_holiday_rules_application():
date_start = datetime.date(year=2021, month=12, day=13) # Monday, even week
slots = agenda.get_custody_slots(date_start, date_start + datetime.timedelta(days=30))
guardians = [x.guardian.name for x in slots]
guardians = [str(x.guardian) for x in slots]
assert all(name == 'John Doe' for name in guardians[:21])
assert all(name == 'Jane Doe' for name in guardians[21:28])
assert all(name == 'John Doe' for name in guardians[28:])
@ -3308,7 +3308,7 @@ def test_shared_custody_agenda_holiday_rules_application():
date_end=datetime.date(year=2021, month=12, day=29),
)
slots = agenda.get_custody_slots(date_start, date_start + datetime.timedelta(days=30))
slots = [(x.date.strftime('%d/%m'), x.guardian.name) for x in slots]
slots = [(x.date.strftime('%d/%m'), str(x.guardian)) for x in slots]
assert slots[13:17] == [
('26/12', 'John Doe'),
('27/12', 'Jane Doe'),
@ -3320,8 +3320,8 @@ def test_shared_custody_agenda_holiday_rules_application():
def test_shared_custody_agenda_update_holiday_rules_command():
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
christmas_holiday = TimePeriodExceptionGroup.objects.create(