I am trying to open a gnuhealth.patient.evaluation
form from an appointment (gnuhealth.appointment
) when clicking the “Open Evaluation” button. However, I am facing an issue where the button does not work as expected. Here is what I have implemented:
- Method in the Appointment Model (
act_open_evaluation
)
@classmethod
@ModelView.button
def act_open_evaluation(cls, appointments):
pool = Pool()
Evaluation = pool.get('gnuhealth.patient.evaluation')
for appointment in appointments:
if not appointment.patient:
raise ValueError("Patient is required to open evaluation")
# Create a new PatientEvaluation entry
evaluation = Evaluation.create([{
'patient': appointment.patient.id,
'appointment': appointment.id,
'evaluation_start': datetime.now(),
'state': 'in_progress',
}])
# Update Appointment state
cls.write([appointment], {'state': 'in_nurse'})
return {
'name': 'Medical Evaluation',
'type': 'ir.action.act_window',
'res_model': 'gnuhealth.patient.evaluation',
'view_mode': 'form',
'view_id': False,
'target': 'current',
'context': {'default_patient': appointment.patient.id},
}
- Button in
appointment.xml
<button name="act_open_evaluation"
string="Open Evaluation"
icon="tryton-go-next"
help="Open the patient evaluation form"
invisible="Eval('state') != 'checked_in'"/>
- Action Definition in
ir.action.act_window
<record model="ir.action.act_window" id="act_open_patient_evaluation">
<field name="name">Open Patient Evaluation</field>
<field name="res_model">gnuhealth.patient.evaluation</field>
<field name="view_mode">form</field>
<field name="view_id" ref="gnuhealth_patient_evaluation_view"/>
</record>
However, when I click the button, the form does not open it only change the state to checked, and there is no clear error message. Am I missing something in the action definition or method implementation? Any guidance would be greatly appreciated.