clinic/netforce_clinic/models/patient_move.py

44 lines
1.8 KiB
Python
Raw Normal View History

2015-07-28 11:58:54 +00:00
import time
2017-09-19 12:10:32 +00:00
from netforce.model import Model, fields, get_model
2015-07-28 11:58:54 +00:00
class PatientMove(Model):
_name="clinic.patient.move"
2017-09-19 12:10:32 +00:00
2015-07-28 11:58:54 +00:00
_fields={
2017-09-19 12:10:32 +00:00
'create_date': fields.DateTime("Create Date", required=True),
'date': fields.Date("Date", search=True, required=True),
'patient_id': fields.Many2One('clinic.patient','Patient', search=True, required=True),
'patient_type_id': fields.Many2One('clinic.patient.type','Patient Type', search=True, required=True),
'location_from_id': fields.Many2One("clinic.department","From Department", search=True, required=True),
'location_to_id': fields.Many2One("clinic.department","To Department", search=True, required=True),
"state": fields.Selection([['new','New'],["move","Move"],['dispose','Dispose']],'State'),
2015-07-28 11:58:54 +00:00
}
_defaults={
2017-09-19 12:10:32 +00:00
'create_date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'date': lambda *a: time.strftime("%Y-%m-%d"),
"state": "new",
2015-07-28 11:58:54 +00:00
}
2017-09-19 12:10:32 +00:00
_order="date desc"
_constraints=["check_location_status"]
def check_location_status(self, ids, context={}):
for obj in self.browse(ids):
if obj.state=='move' and obj.location_from_id.id == obj.location_to_id.id:
raise Exception("Can not move patient the same location!!")
elif obj.state in ('new','dispose') and obj.location_from_id.id != obj.location_to_id.id:
raise Exception("New/Dispose patient should be the same location!!")
def onchange_patient(self, context={}):
data=context['data']
patient_id=data['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
data['patient_type_id']=patient.type_id.id
data['location_from_id']=patient.branch_id.id
return data
2015-07-28 11:58:54 +00:00
2017-09-19 12:10:32 +00:00
PatientMove.register()