clinic/netforce_clinic/models/patient_cycle.py

28 lines
1.1 KiB
Python

from netforce.model import Model, fields
class PatientCycle(Model):
_name="clinic.patient.cycle"
_string="Patient Cycle"
_audit_log=True
_fields={
"patient_id": fields.Many2One('clinic.patient',"Patient",required=True,on_delete="cascade",search=True,domain=[['state','=','admit']]),
"cycle_id": fields.Many2One('clinic.cycle',"Cycle",search=True),
"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()