changeset 5060:48e9240df572

bug #62022: health professional: license id must be unique but can be empty
author Luis Falcon <falcon@gnuhealth.org>
date Tue, 15 Feb 2022 17:32:37 +0000
parents 3369af2e2622
children 7674f337109a
files tryton/health/health.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/health.py
+++ b/tryton/health/health.py
@@ -1833,6 +1833,27 @@
             res = self.name.rec_name
         return res
 
+    # Execute when creating a new record
+    @classmethod
+    def create(cls, vlist):
+        vlist = [x.copy() for x in vlist]
+        # Use None instead of '' to allow null values in code
+        # yet enforcing the unique constraint on the license ID
+        for values in vlist:
+            if values.get('code') == '':
+                values['code'] = None
+        return super(HealthProfessional, cls).create(vlist)
+
+    # Execute on update record
+    @classmethod
+    def write(cls, healthprofs, values):
+        # Use None instead of '' to allow null values in code
+        # yet enforcing the unique constraint on the license ID
+        for healthprof in healthprofs:
+            if values.get('code') == '':
+                values['code'] = None
+        return super(HealthProfessional, cls).write(healthprofs, values)
+
 
 class HealthProfessionalSpecialties(ModelSQL, ModelView):
     'Health Professional Specialties'