Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3205 Widoki

Hello All,

i selected patient from   patient  and open patient form  , And above the patient form i add a button for this button wizard is opened and getting  appointment information .

I want that patient_id filed in   create appointment  wizard should be auto field when user open it

How can i  do this? 


##################### Code ####################

from odoo import models, fields, api



class CreateAppintment(models.TransientModel):

    _name = 'create.appointment'

    patient_id = fields.Many2one('clinic.patient', string='Patient')

    date_appointment = fields.Datetime('Date of Appointment')

    appointment_type = fields.Selection([('type1', 'Medical consultation'), ('type2', 'Check Up')],

                                        string="Appointment Type",

                                        help="To Detect The Type Of Appointment")


    appointment_status = fields.Selection(

        [('Pending', 'Pending'), ('Comfirmed', 'Comfirmed'), ('Done', 'Done'), ('Canceled', 'Canceled')], String="Status",

        readonly=True, default='Pending')

    doctor_id = fields.Many2one('hr.employee', string='Doctor',

                                domain="[('department_id.name', '=', 'Doctors')]")

    notes = fields.Html('Notes')


    def default_get(self):

        pass


        # Create Appointment


    def create_appointment(self):

        vals = {

            'patient_id': self.patient_id.id,

            'doctor_id': self.doctor_id.id,

            'date_appointment': self.date_appointment,

            'appointment_type': self.appointment_type,

            'appointment_status': self.appointment_status,

            'notes': self.notes

        }

        # adding a message to the Chatter from code

        self.patient_id.message_post(body='Test String', subject="Appointment Creation")

        # creating appointments from the code

        self.env['clinic.appointment'].create(vals)



Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can pass the default value using the context, in the question you haven't added shown how you are opening the wizard(code of button),

See this sample for a field, you can pass similar context for button also,

<field name="test" context="{'default_patient_id': active_id}"/>

Thanks

Awatar
Odrzuć
Autor

# code of button in patient model xml to open Create appointment wizard

<button name="%(UP_Clinic.create_appointment_wizard)d" string="Create Appointment" type="action" class="oe_highlight" />

Powiązane posty Odpowiedzi Widoki Czynność
2
sie 25
2200
1
lip 25
748
1
sie 25
1150
0
maj 25
1258
2
kwi 25
3440