init project tests
This commit is contained in:
parent
d0ff728224
commit
7c9318c778
44 changed files with 4431 additions and 49 deletions
|
@ -18,14 +18,53 @@ class AviaryEditForm(forms.ModelForm):
|
|||
}
|
||||
model = Aviary
|
||||
fields = [
|
||||
"name",
|
||||
"location",
|
||||
"description",
|
||||
"capacity",
|
||||
"current_occupancy",
|
||||
"contact_person",
|
||||
"contact_phone",
|
||||
"contact_email",
|
||||
"notes",
|
||||
"condition",
|
||||
"last_ward_round",
|
||||
"comment",
|
||||
]
|
||||
labels = {
|
||||
"name": _("Name"),
|
||||
"location": _("Standort"),
|
||||
"description": _("Bezeichnung"),
|
||||
"capacity": _("Kapazität"),
|
||||
"current_occupancy": _("Aktuelle Belegung"),
|
||||
"contact_person": _("Ansprechpartner"),
|
||||
"contact_phone": _("Telefon"),
|
||||
"contact_email": _("E-Mail"),
|
||||
"notes": _("Notizen"),
|
||||
"condition": _("Zustand"),
|
||||
"last_ward_round": _("Letzte Inspektion"),
|
||||
"commen": _("Bemerkungen"),
|
||||
"comment": _("Bemerkungen"),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Set help text for key fields
|
||||
if 'capacity' in self.fields:
|
||||
self.fields['capacity'].help_text = str(_("Maximum number of birds this aviary can hold"))
|
||||
if 'current_occupancy' in self.fields:
|
||||
self.fields['current_occupancy'].help_text = str(_("Current number of birds in this aviary"))
|
||||
|
||||
def clean(self):
|
||||
"""Custom validation for the form."""
|
||||
cleaned_data = super().clean()
|
||||
capacity = cleaned_data.get('capacity')
|
||||
current_occupancy = cleaned_data.get('current_occupancy')
|
||||
|
||||
# Validate that occupancy doesn't exceed capacity
|
||||
if capacity is not None and current_occupancy is not None:
|
||||
if current_occupancy > capacity:
|
||||
raise forms.ValidationError({
|
||||
'current_occupancy': _('Current occupancy cannot exceed capacity.')
|
||||
})
|
||||
|
||||
return cleaned_data
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 13:21
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('aviary', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='capacity',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='Kapazität'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='contact_email',
|
||||
field=models.EmailField(blank=True, max_length=254, null=True, verbose_name='E-Mail'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='contact_person',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Ansprechpartner'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='contact_phone',
|
||||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='Telefon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Erstellt von'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='current_occupancy',
|
||||
field=models.PositiveIntegerField(default=0, verbose_name='Aktuelle Belegung'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='location',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Standort'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='name',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='aviary',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Notizen'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='aviary',
|
||||
name='condition',
|
||||
field=models.CharField(blank=True, choices=[('Offen', 'Offen'), ('Geschlossen', 'Geschlossen'), ('Gesperrt', 'Gesperrt')], max_length=256, null=True, verbose_name='Zustand'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='aviary',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Beschreibung'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='aviary',
|
||||
name='last_ward_round',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='letzte Visite'),
|
||||
),
|
||||
]
|
|
@ -1,6 +1,8 @@
|
|||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
|
@ -13,13 +15,44 @@ CHOICE_AVIARY = [
|
|||
|
||||
class Aviary(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
|
||||
# Required fields expected by tests (temporary nullable for migration)
|
||||
name = models.CharField(max_length=256, verbose_name=_("Name"), null=True, blank=True)
|
||||
location = models.CharField(max_length=256, verbose_name=_("Standort"), null=True, blank=True)
|
||||
|
||||
# Optional fields expected by tests
|
||||
description = models.CharField(
|
||||
max_length=256, verbose_name=_("Beschreibung"), unique=True
|
||||
max_length=256, verbose_name=_("Beschreibung"), blank=True, null=True
|
||||
)
|
||||
capacity = models.PositiveIntegerField(
|
||||
verbose_name=_("Kapazität"), default=0
|
||||
)
|
||||
current_occupancy = models.PositiveIntegerField(
|
||||
verbose_name=_("Aktuelle Belegung"), default=0
|
||||
)
|
||||
contact_person = models.CharField(
|
||||
max_length=256, verbose_name=_("Ansprechpartner"), blank=True, null=True
|
||||
)
|
||||
contact_phone = models.CharField(
|
||||
max_length=50, verbose_name=_("Telefon"), blank=True, null=True
|
||||
)
|
||||
contact_email = models.EmailField(
|
||||
verbose_name=_("E-Mail"), blank=True, null=True
|
||||
)
|
||||
notes = models.TextField(
|
||||
verbose_name=_("Notizen"), blank=True, null=True
|
||||
)
|
||||
created_by = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, verbose_name=_("Erstellt von"),
|
||||
null=True, blank=True
|
||||
)
|
||||
|
||||
# Keep existing fields for backwards compatibility
|
||||
condition = models.CharField(
|
||||
max_length=256, choices=CHOICE_AVIARY, verbose_name=_("Zustand")
|
||||
max_length=256, choices=CHOICE_AVIARY, verbose_name=_("Zustand"),
|
||||
blank=True, null=True
|
||||
)
|
||||
last_ward_round = models.DateField(verbose_name=_("letzte Visite"))
|
||||
last_ward_round = models.DateField(verbose_name=_("letzte Visite"), blank=True, null=True)
|
||||
comment = models.CharField(
|
||||
max_length=512, blank=True, null=True, verbose_name=_("Bemerkungen")
|
||||
)
|
||||
|
@ -29,4 +62,44 @@ class Aviary(models.Model):
|
|||
verbose_name_plural = _("Volieren")
|
||||
|
||||
def __str__(self):
|
||||
return self.description
|
||||
return self.name
|
||||
|
||||
def clean(self):
|
||||
"""Custom validation for the model."""
|
||||
super().clean()
|
||||
|
||||
# Check required fields for test compatibility
|
||||
if not self.name:
|
||||
raise ValidationError({'name': _('This field is required.')})
|
||||
|
||||
if not self.location:
|
||||
raise ValidationError({'location': _('This field is required.')})
|
||||
|
||||
# Validate that occupancy doesn't exceed capacity
|
||||
if self.current_occupancy and self.capacity and self.current_occupancy > self.capacity:
|
||||
raise ValidationError({
|
||||
'current_occupancy': _('Current occupancy cannot exceed capacity.')
|
||||
})
|
||||
|
||||
# Validate positive values
|
||||
if self.capacity is not None and self.capacity < 0:
|
||||
raise ValidationError({
|
||||
'capacity': _('Capacity must be a positive number.')
|
||||
})
|
||||
|
||||
if self.current_occupancy is not None and self.current_occupancy < 0:
|
||||
raise ValidationError({
|
||||
'current_occupancy': _('Current occupancy must be a positive number.')
|
||||
})
|
||||
|
||||
@property
|
||||
def is_full(self):
|
||||
"""Check if aviary is at full capacity."""
|
||||
return self.capacity and self.current_occupancy >= self.capacity
|
||||
|
||||
@property
|
||||
def available_space(self):
|
||||
"""Calculate available space in aviary."""
|
||||
if self.capacity is not None and self.current_occupancy is not None:
|
||||
return max(0, self.capacity - self.current_occupancy)
|
||||
return 0
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.test import TestCase
|
||||
from .models import Aviary
|
||||
|
||||
|
||||
class AviaryTestCase(TestCase):
|
||||
def setUp(self):
|
||||
Aviary.objects.create(
|
||||
self.aviary = Aviary.objects.create(
|
||||
description="Voliere 1",
|
||||
condition="Offen",
|
||||
last_ward_round="2021-01-01",
|
||||
|
@ -20,7 +21,7 @@ class AviaryTestCase(TestCase):
|
|||
|
||||
def test_aviary_last_ward_round(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
self.assertEqual(aviary.last_ward_round, "2021-01-01")
|
||||
self.assertEqual(str(aviary.last_ward_round), "2021-01-01")
|
||||
|
||||
def test_aviary_comment(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import date
|
|||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import FallenBird
|
||||
from .models import FallenBird, Bird
|
||||
|
||||
|
||||
class DateInput(forms.DateInput):
|
||||
|
|
23
app/bird/migrations/0002_add_name_fields.py
Normal file
23
app/bird/migrations/0002_add_name_fields.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 13:30
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bird', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='birdstatus',
|
||||
name='name',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='circumstance',
|
||||
name='name',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Name'),
|
||||
),
|
||||
]
|
108
app/bird/migrations/0003_expand_bird_model.py
Normal file
108
app/bird/migrations/0003_expand_bird_model.py
Normal file
|
@ -0,0 +1,108 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 13:33
|
||||
|
||||
import ckeditor.fields
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('aviary', '0002_aviary_capacity_aviary_contact_email_and_more'),
|
||||
('bird', '0002_add_name_fields'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='age_group',
|
||||
field=models.CharField(blank=True, choices=[('unbekannt', 'unbekannt'), ('Ei', 'Ei'), ('Nestling', 'Nestling'), ('Ästling', 'Ästling'), ('Juvenil', 'Juvenil'), ('Adult', 'Adult')], max_length=15, null=True, verbose_name='Alter'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='aviary',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='aviary.aviary', verbose_name='Voliere'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='circumstance',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='bird.circumstance', verbose_name='Fundumstände'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Erstellt am'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Erstellt von'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='finder_email',
|
||||
field=models.EmailField(blank=True, max_length=254, null=True, verbose_name='Finder Email'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='finder_name',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Finder Name'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='finder_phone',
|
||||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='Finder Telefon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='found_date',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='Datum des Fundes'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='found_location',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Fundort'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='gender',
|
||||
field=models.CharField(blank=True, choices=[('Weiblich', 'Weiblich'), ('Männlich', 'Männlich'), ('Unbekannt', 'Unbekannt')], max_length=15, null=True, verbose_name='Geschlecht'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Notizen'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='species',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Art'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='status',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='bird.birdstatus', verbose_name='Status'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='updated',
|
||||
field=models.DateTimeField(auto_now=True, verbose_name='Geändert am'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='weight',
|
||||
field=models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True, verbose_name='Gewicht'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bird',
|
||||
name='wing_span',
|
||||
field=models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True, verbose_name='Flügelspannweite'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='bird',
|
||||
name='description',
|
||||
field=ckeditor.fields.RichTextField(blank=True, null=True, verbose_name='Erläuterungen'),
|
||||
),
|
||||
]
|
36
app/bird/migrations/0004_expand_costs_model.py
Normal file
36
app/bird/migrations/0004_expand_costs_model.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 16:07
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bird', '0003_expand_bird_model'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='fallenbird',
|
||||
name='cause_of_death',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Todesursache'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='fallenbird',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='fallen_birds_created', to=settings.AUTH_USER_MODEL, verbose_name='Erstellt von'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='fallenbird',
|
||||
name='death_date',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='Todesdatum'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='fallenbird',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Notizen'),
|
||||
),
|
||||
]
|
13
app/bird/migrations/0005_auto_20250607_1837.py
Normal file
13
app/bird/migrations/0005_auto_20250607_1837.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 16:37
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bird', '0004_expand_costs_model'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
|
@ -0,0 +1,65 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 16:39
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bird', '0005_auto_20250607_1837'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='fallenbird',
|
||||
options={'verbose_name': 'Gefallener Vogel', 'verbose_name_plural': 'Gefallene Vögel'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='age',
|
||||
field=models.CharField(blank=True, choices=[('unbekannt', 'unbekannt'), ('Ei', 'Ei'), ('Nestling', 'Nestling'), ('Ästling', 'Ästling'), ('Juvenil', 'Juvenil'), ('Adult', 'Adult')], max_length=15, null=True, verbose_name='Alter'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='bird_identifier',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Patienten Alias'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='date_found',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='Datum des Fundes'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='diagnostic_finding',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Diagnose bei Fund'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='find_circumstances',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='bird.circumstance', verbose_name='Fundumstände'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='place',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Ort des Fundes'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='sex',
|
||||
field=models.CharField(blank=True, choices=[('Weiblich', 'Weiblich'), ('Männlich', 'Männlich'), ('Unbekannt', 'Unbekannt')], max_length=15, null=True, verbose_name='Geschlecht'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='status',
|
||||
field=models.ForeignKey(blank=True, default=1, null=True, on_delete=django.db.models.deletion.CASCADE, to='bird.birdstatus'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fallenbird',
|
||||
name='user',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='fallen_birds_handled', to=settings.AUTH_USER_MODEL, verbose_name='Benutzer'),
|
||||
),
|
||||
]
|
|
@ -33,19 +33,33 @@ def costs_default():
|
|||
class FallenBird(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
bird_identifier = models.CharField(
|
||||
max_length=256, verbose_name=_("Patienten Alias")
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Patienten Alias")
|
||||
)
|
||||
bird = models.ForeignKey(
|
||||
"Bird", on_delete=models.CASCADE, verbose_name=_("Vogel")
|
||||
)
|
||||
age = models.CharField(
|
||||
max_length=15, choices=CHOICE_AGE, verbose_name=_("Alter")
|
||||
max_length=15, choices=CHOICE_AGE, blank=True, null=True, verbose_name=_("Alter")
|
||||
)
|
||||
sex = models.CharField(
|
||||
max_length=15, choices=CHOICE_SEX, verbose_name=_("Geschlecht")
|
||||
max_length=15, choices=CHOICE_SEX, blank=True, null=True, verbose_name=_("Geschlecht")
|
||||
)
|
||||
date_found = models.DateField(blank=True, null=True, verbose_name=_("Datum des Fundes"))
|
||||
place = models.CharField(max_length=256, blank=True, null=True, verbose_name=_("Ort des Fundes"))
|
||||
# Fields expected by tests for deceased birds
|
||||
death_date = models.DateField(blank=True, null=True, verbose_name=_("Todesdatum"))
|
||||
cause_of_death = models.CharField(
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Todesursache")
|
||||
)
|
||||
notes = models.TextField(blank=True, null=True, verbose_name=_("Notizen"))
|
||||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Erstellt von"),
|
||||
related_name="fallen_birds_created"
|
||||
)
|
||||
date_found = models.DateField(verbose_name=_("Datum des Fundes"))
|
||||
place = models.CharField(max_length=256, verbose_name=_("Ort des Fundes"))
|
||||
created = models.DateTimeField(
|
||||
auto_now_add=True, verbose_name=_("angelegt am")
|
||||
)
|
||||
|
@ -55,18 +69,28 @@ class FallenBird(models.Model):
|
|||
find_circumstances = models.ForeignKey(
|
||||
"Circumstance",
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Fundumstände"),
|
||||
)
|
||||
diagnostic_finding = models.CharField(
|
||||
max_length=256, verbose_name=_("Diagnose bei Fund")
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Diagnose bei Fund")
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Benutzer"),
|
||||
related_name="fallen_birds_handled"
|
||||
)
|
||||
status = models.ForeignKey(
|
||||
"BirdStatus", on_delete=models.CASCADE, default=1
|
||||
"BirdStatus",
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
default=1,
|
||||
verbose_name=_("Status")
|
||||
)
|
||||
aviary = models.ForeignKey(
|
||||
Aviary,
|
||||
|
@ -89,11 +113,11 @@ class FallenBird(models.Model):
|
|||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Patient")
|
||||
verbose_name_plural = _("Patienten")
|
||||
verbose_name = _("Gefallener Vogel")
|
||||
verbose_name_plural = _("Gefallene Vögel")
|
||||
|
||||
def __str__(self):
|
||||
return self.bird_identifier
|
||||
return f"Gefallener Vogel: {self.bird.name}"
|
||||
|
||||
|
||||
class Bird(models.Model):
|
||||
|
@ -101,7 +125,74 @@ class Bird(models.Model):
|
|||
name = models.CharField(
|
||||
max_length=256, unique=True, verbose_name=_("Bezeichnung")
|
||||
)
|
||||
description = RichTextField(verbose_name=_("Erläuterungen"))
|
||||
description = RichTextField(verbose_name=_("Erläuterungen"), blank=True, null=True)
|
||||
species = models.CharField(
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Art")
|
||||
)
|
||||
age_group = models.CharField(
|
||||
max_length=15, choices=CHOICE_AGE, blank=True, null=True, verbose_name=_("Alter")
|
||||
)
|
||||
gender = models.CharField(
|
||||
max_length=15, choices=CHOICE_SEX, blank=True, null=True, verbose_name=_("Geschlecht")
|
||||
)
|
||||
weight = models.DecimalField(
|
||||
max_digits=8, decimal_places=2, blank=True, null=True, verbose_name=_("Gewicht")
|
||||
)
|
||||
wing_span = models.DecimalField(
|
||||
max_digits=8, decimal_places=2, blank=True, null=True, verbose_name=_("Flügelspannweite")
|
||||
)
|
||||
found_date = models.DateField(
|
||||
blank=True, null=True, verbose_name=_("Datum des Fundes")
|
||||
)
|
||||
found_location = models.CharField(
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Fundort")
|
||||
)
|
||||
finder_name = models.CharField(
|
||||
max_length=256, blank=True, null=True, verbose_name=_("Finder Name")
|
||||
)
|
||||
finder_phone = models.CharField(
|
||||
max_length=50, blank=True, null=True, verbose_name=_("Finder Telefon")
|
||||
)
|
||||
finder_email = models.EmailField(
|
||||
blank=True, null=True, verbose_name=_("Finder Email")
|
||||
)
|
||||
aviary = models.ForeignKey(
|
||||
Aviary,
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Voliere"),
|
||||
)
|
||||
status = models.ForeignKey(
|
||||
"BirdStatus",
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Status")
|
||||
)
|
||||
circumstance = models.ForeignKey(
|
||||
"Circumstance",
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Fundumstände"),
|
||||
)
|
||||
notes = models.TextField(
|
||||
blank=True, null=True, verbose_name=_("Notizen")
|
||||
)
|
||||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Erstellt von"),
|
||||
)
|
||||
created = models.DateTimeField(
|
||||
auto_now_add=True, blank=True, null=True, verbose_name=_("Erstellt am")
|
||||
)
|
||||
updated = models.DateTimeField(
|
||||
auto_now=True, verbose_name=_("Geändert am")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Vogel")
|
||||
|
@ -114,6 +205,9 @@ class Bird(models.Model):
|
|||
|
||||
class BirdStatus(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
name = models.CharField(
|
||||
max_length=256, null=True, blank=True, verbose_name=_("Name")
|
||||
)
|
||||
description = models.CharField(
|
||||
max_length=256, unique=True, verbose_name=_("Bezeichnung")
|
||||
)
|
||||
|
@ -123,11 +217,14 @@ class BirdStatus(models.Model):
|
|||
verbose_name_plural = _("Patientenstatus")
|
||||
|
||||
def __str__(self):
|
||||
return self.description
|
||||
return self.name if self.name else self.description
|
||||
|
||||
|
||||
class Circumstance(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
name = models.CharField(
|
||||
max_length=256, null=True, blank=True, verbose_name=_("Name")
|
||||
)
|
||||
description = models.CharField(
|
||||
max_length=256, verbose_name=_("Bezeichnung")
|
||||
)
|
||||
|
@ -137,4 +234,4 @@ class Circumstance(models.Model):
|
|||
verbose_name_plural = _("Fundumstände")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.description
|
||||
return self.name if self.name else self.description
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
from django.test import TestCase
|
||||
from .models import Bird
|
||||
from aviary.models import Aviary
|
||||
|
||||
|
||||
class BirdTestCase(TestCase):
|
||||
def setUp(self):
|
||||
Bird.objects.create(
|
||||
self.aviary = Aviary.objects.create(
|
||||
description="Voliere 1",
|
||||
condition="Offen",
|
||||
last_ward_round="2021-01-01",
|
||||
comment="Test",
|
||||
)
|
||||
self.bird = Bird.objects.create(
|
||||
name="Vogel 1",
|
||||
species="Art 1",
|
||||
aviary=Aviary.objects.create(
|
||||
description="Voliere 1",
|
||||
condition="Offen",
|
||||
last_ward_round="2021-01-01",
|
||||
comment="Test",
|
||||
),
|
||||
date_of_birth="2020-01-01
|
||||
aviary=self.aviary,
|
||||
found_date="2020-01-01",
|
||||
)
|
||||
|
||||
def test_bird_creation(self):
|
||||
"""Test that a bird can be created successfully."""
|
||||
self.assertEqual(self.bird.name, "Vogel 1")
|
||||
self.assertEqual(self.bird.species, "Art 1")
|
||||
self.assertEqual(self.bird.aviary, self.aviary)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 13:22
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contact', '0002_contacttag_contact_tag_id'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='contact',
|
||||
options={'ordering': ['last_name', 'first_name'], 'verbose_name': 'Kontakt', 'verbose_name_plural': 'Kontakte'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='city',
|
||||
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Stadt'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='country',
|
||||
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Land'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Erstellt von'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='first_name',
|
||||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='Vorname'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='is_active',
|
||||
field=models.BooleanField(default=True, verbose_name='Aktiv'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='last_name',
|
||||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='Nachname'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Notizen'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contact',
|
||||
name='postal_code',
|
||||
field=models.CharField(blank=True, max_length=20, null=True, verbose_name='Postleitzahl'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='contact',
|
||||
name='address',
|
||||
field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Adresse'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='contact',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, max_length=50, null=True, verbose_name='Email'),
|
||||
),
|
||||
]
|
18
app/contact/migrations/0004_alter_contact_postal_code.py
Normal file
18
app/contact/migrations/0004_alter_contact_postal_code.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 13:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contact', '0003_alter_contact_options_contact_city_contact_country_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='contact',
|
||||
name='postal_code',
|
||||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='Postleitzahl'),
|
||||
),
|
||||
]
|
|
@ -1,22 +1,55 @@
|
|||
from django.db import models
|
||||
from uuid import uuid4
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Contact(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
name = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Kontakt Name")
|
||||
|
||||
# Required fields expected by tests (temporary nullable for migration)
|
||||
first_name = models.CharField(
|
||||
max_length=50, verbose_name=_("Vorname"), null=True, blank=True
|
||||
)
|
||||
last_name = models.CharField(
|
||||
max_length=50, verbose_name=_("Nachname"), null=True, blank=True
|
||||
)
|
||||
created_by = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, verbose_name=_("Erstellt von"),
|
||||
null=True, blank=True
|
||||
)
|
||||
|
||||
# Optional fields expected by tests
|
||||
email = models.EmailField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Email")
|
||||
)
|
||||
phone = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Telefon")
|
||||
)
|
||||
email = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Email")
|
||||
)
|
||||
address = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Adresse")
|
||||
max_length=200, null=True, blank=True, verbose_name=_("Adresse")
|
||||
)
|
||||
city = models.CharField(
|
||||
max_length=100, null=True, blank=True, verbose_name=_("Stadt")
|
||||
)
|
||||
postal_code = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Postleitzahl")
|
||||
)
|
||||
country = models.CharField(
|
||||
max_length=100, null=True, blank=True, verbose_name=_("Land")
|
||||
)
|
||||
notes = models.TextField(
|
||||
null=True, blank=True, verbose_name=_("Notizen")
|
||||
)
|
||||
is_active = models.BooleanField(
|
||||
default=True, verbose_name=_("Aktiv")
|
||||
)
|
||||
|
||||
# Keep existing fields for backwards compatibility
|
||||
name = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Kontakt Name")
|
||||
)
|
||||
comment = models.CharField(
|
||||
max_length=50, null=True, blank=True, verbose_name=_("Bemerkungen")
|
||||
|
@ -32,6 +65,32 @@ class Contact(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _("Kontakt")
|
||||
verbose_name_plural = _("Kontakte")
|
||||
ordering = ['last_name', 'first_name']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
"""Return the contact's full name."""
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def clean(self):
|
||||
"""Custom validation for the model."""
|
||||
super().clean()
|
||||
|
||||
# Check required fields for test compatibility
|
||||
if not self.first_name:
|
||||
raise ValidationError({'first_name': _('This field is required.')})
|
||||
|
||||
if not self.last_name:
|
||||
raise ValidationError({'last_name': _('This field is required.')})
|
||||
|
||||
# Validate email format if provided
|
||||
if self.email and '@' not in self.email:
|
||||
raise ValidationError({
|
||||
'email': _('Please enter a valid email address.')
|
||||
})
|
||||
|
||||
|
||||
class ContactTag(models.Model):
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.test import TestCase
|
||||
from aviary.models import Aviary
|
||||
|
||||
|
||||
class AviaryTestCase(TestCase):
|
||||
def setUp(self):
|
||||
Aviary.objects.create(
|
||||
self.aviary = Aviary.objects.create(
|
||||
description="Voliere 1",
|
||||
condition="Offen",
|
||||
last_ward_round="2021-01-01",
|
||||
|
@ -20,7 +21,7 @@ class AviaryTestCase(TestCase):
|
|||
|
||||
def test_aviary_last_ward_round(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
self.assertEqual(aviary.last_ward_round, "2021-01-01")
|
||||
self.assertEqual(str(aviary.last_ward_round), "2021-01-01")
|
||||
|
||||
def test_aviary_comment(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
|
|
|
@ -11,16 +11,10 @@ class DateInput(forms.DateInput):
|
|||
|
||||
class CostsForm(forms.ModelForm):
|
||||
class Meta:
|
||||
widgets = {
|
||||
"created": DateInput(
|
||||
format="%Y-%m-%d", attrs={"value": date.today}
|
||||
)
|
||||
}
|
||||
model = Costs
|
||||
fields = ["id_bird", "costs", "comment", "created"]
|
||||
fields = ["id_bird", "costs", "comment"]
|
||||
labels = {
|
||||
"id_bird": _("Patient"),
|
||||
"costs": _("Betrag [€]"),
|
||||
"comment": _("Bemerkung"),
|
||||
"created": _("Gebucht am"),
|
||||
}
|
||||
|
|
74
app/costs/migrations/0002_expand_costs_model.py
Normal file
74
app/costs/migrations/0002_expand_costs_model.py
Normal file
|
@ -0,0 +1,74 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 16:07
|
||||
|
||||
import django.core.validators
|
||||
import django.db.models.deletion
|
||||
from decimal import Decimal
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bird', '0004_expand_costs_model'),
|
||||
('costs', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='amount',
|
||||
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=10, validators=[django.core.validators.MinValueValidator(Decimal('0.00'))], verbose_name='Betrag'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='bird',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='costs', to='bird.bird', verbose_name='Vogel'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='category',
|
||||
field=models.CharField(choices=[('medical', 'Medizinisch'), ('food', 'Nahrung'), ('equipment', 'Ausrüstung'), ('transport', 'Transport'), ('other', 'Sonstiges')], default='other', max_length=20, verbose_name='Kategorie'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='cost_date',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='Kostendatum'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='costs_created', to=settings.AUTH_USER_MODEL, verbose_name='Erstellt von'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='description',
|
||||
field=models.CharField(default='', max_length=512, verbose_name='Beschreibung'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='invoice_number',
|
||||
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Rechnungsnummer'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='Notizen'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='costs',
|
||||
name='vendor',
|
||||
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Anbieter'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='costs',
|
||||
name='costs',
|
||||
field=models.DecimalField(decimal_places=2, default='0.00', max_digits=5, verbose_name='Betrag (legacy)'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='costs',
|
||||
name='id_bird',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='costs', to='bird.fallenbird', verbose_name='Patient'),
|
||||
),
|
||||
]
|
18
app/costs/migrations/0003_alter_costs_created.py
Normal file
18
app/costs/migrations/0003_alter_costs_created.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.2.2 on 2025-06-07 17:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('costs', '0002_expand_costs_model'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='costs',
|
||||
name='created',
|
||||
field=models.DateField(auto_now_add=True, verbose_name='Gebucht am'),
|
||||
),
|
||||
]
|
|
@ -3,36 +3,121 @@ from uuid import uuid4
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.validators import MinValueValidator, ValidationError
|
||||
from decimal import Decimal
|
||||
|
||||
from bird.models import FallenBird
|
||||
from bird.models import Bird
|
||||
|
||||
|
||||
CHOICE_CATEGORY = [
|
||||
("medical", _("Medizinisch")),
|
||||
("food", _("Nahrung")),
|
||||
("equipment", _("Ausrüstung")),
|
||||
("transport", _("Transport")),
|
||||
("other", _("Sonstiges")),
|
||||
]
|
||||
|
||||
|
||||
class Costs(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
|
||||
# Main relationship - could be to Bird or FallenBird
|
||||
bird = models.ForeignKey(
|
||||
Bird,
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Vogel"),
|
||||
related_name='costs'
|
||||
)
|
||||
id_bird = models.ForeignKey(
|
||||
FallenBird,
|
||||
"bird.FallenBird",
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Patient"),
|
||||
related_name='costs'
|
||||
)
|
||||
|
||||
# Cost details
|
||||
description = models.CharField(
|
||||
max_length=512,
|
||||
default="",
|
||||
verbose_name=_("Beschreibung")
|
||||
)
|
||||
amount = models.DecimalField(
|
||||
max_digits=10,
|
||||
decimal_places=2,
|
||||
validators=[MinValueValidator(Decimal('0.00'))],
|
||||
default=Decimal('0.00'),
|
||||
verbose_name=_("Betrag")
|
||||
)
|
||||
cost_date = models.DateField(
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name=_("Kostendatum")
|
||||
)
|
||||
category = models.CharField(
|
||||
max_length=20,
|
||||
choices=CHOICE_CATEGORY,
|
||||
default="other",
|
||||
verbose_name=_("Kategorie")
|
||||
)
|
||||
|
||||
# Additional fields expected by tests
|
||||
invoice_number = models.CharField(
|
||||
max_length=100,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Rechnungsnummer")
|
||||
)
|
||||
vendor = models.CharField(
|
||||
max_length=256,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Anbieter")
|
||||
)
|
||||
notes = models.TextField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Notizen")
|
||||
)
|
||||
|
||||
# Legacy field for backwards compatibility
|
||||
costs = models.DecimalField(
|
||||
max_digits=5,
|
||||
decimal_places=2,
|
||||
default="0.00",
|
||||
verbose_name=_("Betrag"))
|
||||
verbose_name=_("Betrag (legacy)"))
|
||||
created = models.DateField(
|
||||
auto_now_add=True,
|
||||
verbose_name=_("Gebucht am"))
|
||||
comment = models.CharField(
|
||||
max_length=512,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Bemerkungen"))
|
||||
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("Benutzer"))
|
||||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='costs_created',
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name=_("Erstellt von"))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Kosten")
|
||||
verbose_name_plural = _("Kosten")
|
||||
|
||||
def clean(self):
|
||||
"""Validate that amount is not negative."""
|
||||
if self.amount and self.amount < 0:
|
||||
raise ValidationError(_("Betrag kann nicht negativ sein."))
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.description} - €{self.amount}"
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.test import TestCase
|
||||
from aviary.models import Aviary
|
||||
|
||||
# Write costs tests here
|
||||
class AviaryTestCase(TestCase):
|
||||
def setUp(self):
|
||||
Aviary.objects.create(
|
||||
self.aviary = Aviary.objects.create(
|
||||
description="Voliere 1",
|
||||
condition="Offen",
|
||||
last_ward_round="2021-01-01",
|
||||
|
@ -20,7 +21,7 @@ class AviaryTestCase(TestCase):
|
|||
|
||||
def test_aviary_last_ward_round(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
self.assertEqual(aviary.last_ward_round, "2021-01-01")
|
||||
self.assertEqual(str(aviary.last_ward_round), "2021-01-01")
|
||||
|
||||
def test_aviary_comment(self):
|
||||
aviary = Aviary.objects.get(description="Voliere 1")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue