changeset 3430:cb5c2094a22e

HMIS server. health. Fix bug related to HP specialties https://savannah.gnu.org/bugs/?57148 - Use editable tree view on HP specialty. Much faster coding . - Make required both HP and specialty fields, avoiding empty entries. - Allow search the name of main specialty - Set unique constraint on specialty associated to the HP
author Luis Falcon <falcon@gnuhealth.org>
date Fri, 01 Nov 2019 14:22:47 +0000
parents 8714dec41129
children 3a97892bcf1e
files tryton/health/health.py tryton/health/view/gnuhealth_hp_specialty_tree.xml
diffstat 2 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/health.py
+++ b/tryton/health/health.py
@@ -1887,14 +1887,34 @@
     'Health Professional Specialties'
     __name__ = 'gnuhealth.hp_specialty'
 
-    name = fields.Many2One('gnuhealth.healthprofessional', 'Health Professional')
+    name = fields.Many2One('gnuhealth.healthprofessional', \
+            'Health Professional', required=True)
 
     specialty = fields.Many2One(
-        'gnuhealth.specialty', 'Specialty', help='Specialty Code')
+        'gnuhealth.specialty', 'Specialty', required=True, \
+            help='Specialty Code')
 
     def get_rec_name(self, name):
         return self.specialty.name
 
+    @classmethod
+    def search_rec_name(cls, name, clause):
+        if clause[1].startswith('!') or clause[1].startswith('not '):
+            bool_op = 'AND'
+        else:
+            bool_op = 'OR'
+        return [bool_op,
+            ('specialty',) + tuple(clause[1:]),
+            ]
+    @classmethod
+    def __setup__(cls):
+        super(HealthProfessionalSpecialties, cls).__setup__()
+        t = cls.__table__()
+        cls._sql_constraints = [
+            ('name_uniq', Unique(t,t.name, t.specialty), \
+                'This specialty is already assigned to the Health Professional'),
+        ]
+
 
 class PhysicianSP(ModelSQL, ModelView):
     # Add Main Specialty field after from the Health Professional Speciality
--- a/tryton/health/view/gnuhealth_hp_specialty_tree.xml
+++ b/tryton/health/view/gnuhealth_hp_specialty_tree.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tree>
+<tree editable="1">
     <field name="specialty"/>
     <field name="name"/>
 </tree>