diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 0b7c708..6f92c8b 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -71,13 +71,14 @@ class Patient(Model): res={} for obj in self.browse(ids): dpt_codes=set() + # main department + dpt_codes.update({obj.department_id.code}) + # hd department for dpt in obj.departments: dpt_codes.update({dpt.code}) - if not dpt_codes: - for cline in obj.cycles: - dpt_codes.update({cline.department_id.code}) - if not dpt_codes: - dpt_codes=[obj.department_id.code] + # cycle settings + for cline in obj.cycles: + dpt_codes.update({cline.department_id.code}) res[obj.id]=','.join([code for code in dpt_codes if code]) return res diff --git a/netforce_clinic/models/patient_cycle.py b/netforce_clinic/models/patient_cycle.py index 21cf13e..0ed861e 100644 --- a/netforce_clinic/models/patient_cycle.py +++ b/netforce_clinic/models/patient_cycle.py @@ -10,6 +10,17 @@ class PatientCycle(Model): "department_id": fields.Many2One('clinic.department',"Department",search=True), 'day': fields.Selection([('mon', 'Monday'), ('tue','Tuesday'), ('wed','Wednesday'),('thu','Thursday'),('fri','Friday'),('sat','Saturday'),('sun','Sunday')], 'Day',search=True), } + + def _get_department(self,context={}): + data=context.get('data') + if data and data.get('department_id'): + return data['department_id'] + + _defaults={ + 'department_id': _get_department, + } + _sql_constraints=("pcycle_uniq","unique(patient_id,cycle_id,day,department_id)","patient_id,cycle_id,day,department_id should be unique"), + _order="department_id,cycle_id" PatientCycle.register()