Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4230 Представления

Hello Community,

I have a question as a beginner using Odoo.  Suppose one is making a hospital system model on Odoo , then created a patient model and an appointment model. Now if someone created an appointment from appointment home page it should be a wizard message with info to create an appointment date with the patient's name field manually to be entered, but if someone entered through patient home page, I want the patient name to be filled automatically from the entered patient record to the appointment's patient field. 


I tried with a code like this


class CreateAppointmentWizard(models.TransientModel):

_name = "create.appointment.wizard"
_inherit=["hospital.patient"]
_description = "Appointment Wizard"

name = fields.Char(string='Name', required=True)
patient_id = fields.Many2one('hospital.patient', string="Patient")


def action_create_appointment(self):
if self.env['hospital.patient']: // patient model
self.patient_id = self.env['hospital.patient'].patient_id
else:
self.patient_id = ''


I need a help in this if it is possible


Thank you

Аватар
Отменить
Автор Лучший ответ

So for future reference anyone new like me asking the same question.

The answer was using active_id in a get function inside the form.

def default_get(self, fields):

result = super(ClassName, self).default_get(fields)
result['patient_id'] = self._context.get('active_id')
return result

Turns out it was easier than I thought lol.


Best regards;

Hadi Hamad




Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июн. 21
3739
1
дек. 19
3497
1
окт. 15
6411
2
сент. 23
4514
1
мая 23
2760