changeset 5062:5c5c827c0305

Fix bug #62025: Appointments only for health professionals? [x] Add "required" argument to get_health_professional method when the health prof field is optional [x] Initialize to None health institution
author Luis Falcon <falcon@gnuhealth.org>
date Wed, 16 Feb 2022 15:26:13 +0000
parents 7674f337109a
children ffc27c3ecc25
files tryton/health/core.py tryton/health/health.py
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/core.py
+++ b/tryton/health/core.py
@@ -126,9 +126,12 @@
             return int(institution_id[0])
 
 
-def get_health_professional():
+def get_health_professional(required=True):
     # Get the professional associated to the internal user id
     # that logs into GNU Health
+    # If the method is called with the arg "required" as False, then
+    # the error message won't be shown in the case of not finding
+    # the corresponding healthprof (eg, creating a new appointment)
     cursor = Transaction().connection.cursor()
     User = Pool().get('res.user')
     user = User(Transaction().user)
@@ -144,6 +147,7 @@
         if (healthprof_id):
             return int(healthprof_id[0])
     else:
-        raise NoAssociatedHealthProfessional(gettext(
-            ('health.msg_no_associated_health_professional'))
-        )
+        if required:
+            raise NoAssociatedHealthProfessional(gettext(
+                ('health.msg_no_associated_health_professional'))
+            )
--- a/tryton/health/health.py
+++ b/tryton/health/health.py
@@ -3451,7 +3451,7 @@
 
     @staticmethod
     def default_healthprof():
-        return get_health_professional()
+        return get_health_professional(required=False)
 
     @staticmethod
     def default_urgency():
@@ -3496,7 +3496,8 @@
 
         # Retrieve the health professional Main specialty, if assigned
 
-        hp_party_id = get_health_professional()
+        hp_party_id = get_health_professional(required=False)
+        hp_main_specialty = None
 
         if hp_party_id:
             # Retrieve the health professional Main specialty, if assigned