diff --git a/app/utils/cert_acess.py b/app/utils/cert_acess.py
index 9d622e7a..76145df3 100644
--- a/app/utils/cert_acess.py
+++ b/app/utils/cert_acess.py
@@ -113,7 +113,7 @@ def get_certificate_data(ind, user_id):
"herd": herd,
"fullname": fullname,
"issue_date": date,
- "photos": False,
+ "photos": "Ja" if ind["has_photo"] else "Nej",
}
ind["notes"] = ".\r\n ".join(
[
diff --git a/app/utils/database.py b/app/utils/database.py
index d775fe64..c909b393 100644
--- a/app/utils/database.py
+++ b/app/utils/database.py
@@ -35,7 +35,7 @@
)
from playhouse.migrate import PostgresqlMigrator, SqliteMigrator, migrate
-CURRENT_SCHEMA_VERSION = 9
+CURRENT_SCHEMA_VERSION = 10
DB_PROXY = Proxy()
DATABASE = None
DATABASE_MIGRATOR = None
@@ -566,6 +566,7 @@ class Individual(BaseModel):
belly_color = TextField(null=True)
hair_notes = TextField(null=True)
is_active = BooleanField(null=True, default=True)
+ has_photo = BooleanField(null=True, default=False)
butchered = BooleanField(null=True, default=False)
castration_date = DateField(null=True, default=None)
@@ -1595,6 +1596,35 @@ def migrate_8_to_9():
).execute()
+def migrate_9_to_10():
+ """
+ Migrate between schema version 9 and 10.
+ """
+ with DATABASE.atomic():
+ if "individual" not in DATABASE.get_tables():
+ # Can't run migration
+ SchemaHistory.insert( # pylint: disable=E1120
+ version=10,
+ comment="not yet bootstrapped, skipping",
+ applied=datetime.now(),
+ ).execute()
+ return
+
+ cols = [x.name for x in DATABASE.get_columns("individual")]
+
+ if "has_photo" not in cols:
+ migrate(
+ DATABASE_MIGRATOR.add_column(
+ "individual",
+ "has_photo",
+ BooleanField(null=True, default=False),
+ )
+ )
+ SchemaHistory.insert( # pylint: disable=E1120
+ version=10, comment="Add has_photo to individual", applied=datetime.now()
+ ).execute()
+
+
def check_migrations():
"""
Check if the database needs any migrations run and run those if that's the case.
diff --git a/frontend/src/data_context_global.tsx b/frontend/src/data_context_global.tsx
index 3b685732..e49010e6 100644
--- a/frontend/src/data_context_global.tsx
+++ b/frontend/src/data_context_global.tsx
@@ -66,6 +66,7 @@ export interface Individual extends LimitedIndividual {
herd_active: boolean;
is_active: boolean;
is_registered: boolean;
+ has_photo: boolean;
alive: boolean;
belly_color: string | null;
eye_color: string | null;
diff --git a/frontend/src/individual_certificate.tsx b/frontend/src/individual_certificate.tsx
index f2030d28..2b7cc50e 100644
--- a/frontend/src/individual_certificate.tsx
+++ b/frontend/src/individual_certificate.tsx
@@ -113,6 +113,7 @@ export function IndividualCertificate({
name: individual?.name,
litter_size: individual?.litter_size,
litter_size6w: individual?.litter_size6w,
+ has_photo: individual?.has_photo,
notes: individual?.notes,
sex: individual?.sex,
genebank: individual?.genebank,
diff --git a/frontend/src/individual_form.tsx b/frontend/src/individual_form.tsx
index 33f360ad..46ef3db8 100644
--- a/frontend/src/individual_form.tsx
+++ b/frontend/src/individual_form.tsx
@@ -50,7 +50,7 @@ export function IndividualForm({
intygError,
herdOptions,
}: {
- genebank: Genebank;
+ genebank?: Genebank;
individual: Individual;
onUpdateIndividual: any;
formAction: FormAction;
@@ -105,10 +105,9 @@ export function IndividualForm({
];
const photoOptions = [
- { value: "no", label: "Nej" },
- { value: "yes", label: "Ja" },
- ]; //should be boolean but doesn't work together with the OptionType
- // also decide how this should be stored in the backend
+ { value: false, label: "Nej" },
+ { value: true, label: "Ja" },
+ ];
return (
<>
@@ -493,6 +492,11 @@ export function IndividualForm({
options={photoOptions ?? []}
className="controlWidth"
getOptionLabel={(option: OptionType) => option.label}
+ value={
+ photoOptions.find(
+ (option) => option.value == individual.has_photo
+ ) ?? photoOptions[0] //"nej as defult pos 0 "
+ }
renderInput={(params) => (