From 8d12f61e2e8ae838a7942cbfce00690b035ddbb2 Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Wed, 16 Feb 2022 12:12:26 +0100
Subject: [PATCH] GREG-214: Adding acronyms as well to dropdown for untis

---
 frontend/src/hooks/useOus/index.tsx                     | 1 +
 frontend/src/routes/sponsor/register/stepPersonForm.tsx | 3 ++-
 greg/api/serializers/organizational_unit.py             | 2 +-
 greg/models.py                                          | 9 +++++++++
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/frontend/src/hooks/useOus/index.tsx b/frontend/src/hooks/useOus/index.tsx
index c2f1205b..ba1a2119 100644
--- a/frontend/src/hooks/useOus/index.tsx
+++ b/frontend/src/hooks/useOus/index.tsx
@@ -6,6 +6,7 @@ type OuData = {
   nb: string
   en: string
   orgreg_id?: string
+  acronym_nob?: string
 }
 
 function useOus(): OuData[] | undefined {
diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
index eadf6d0f..c018bf8a 100644
--- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx
+++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
@@ -243,7 +243,8 @@ const StepPersonForm = forwardRef(
                   .sort(i18n.language === 'en' ? enSort : nbSort)
                   .map((ou) => (
                     <MenuItem key={ou.id.toString()} value={ou.id}>
-                      {getOuName(ou)} ({ou.orgreg_id ?? ''})
+                      {getOuName(ou)} ({ou.acronym_nob ?? ''}) (
+                      {ou.orgreg_id ?? ''})
                     </MenuItem>
                   ))}
               </TextField>
diff --git a/greg/api/serializers/organizational_unit.py b/greg/api/serializers/organizational_unit.py
index 15130f4f..c9339ccf 100644
--- a/greg/api/serializers/organizational_unit.py
+++ b/greg/api/serializers/organizational_unit.py
@@ -29,4 +29,4 @@ class SponsorOrgUnitsSerializer(ModelSerializer):
 
     class Meta:
         model = OrganizationalUnit
-        fields = ["id", "nb", "en", "orgreg_id"]
+        fields = ["id", "nb", "en", "orgreg_id", "acronym_nob"]
diff --git a/greg/models.py b/greg/models.py
index c75a5dd2..d604e78a 100644
--- a/greg/models.py
+++ b/greg/models.py
@@ -482,6 +482,15 @@ class OrganizationalUnit(BaseModel):
             .first()
         )
 
+    @property
+    def acronym_nob(self) -> Optional[str]:
+        """Gets the Norwegian bokmaal acronym if it exists"""
+        return (
+            self.identifiers.filter(name="acronym_nob")
+                .values_list("value", flat=True)
+                .first()
+        )
+
     def __repr__(self) -> str:
         return "{}(id={!r}, name_en={!r}, parent={!r})".format(
             self.__class__.__name__, self.pk, self.name_en, self.parent
-- 
GitLab