0
votes

I have hospital appointment registration model that is relates to lab test model :

'lab_test_ids': fields.one2many('oeh.medical.lab.test','apoointment','Lab Tests', readonly=False,states={'Completed': [('readonly', True)]}),

in the view I have a TAB (page) under appointment form :

page string="Lab Tests"> <field name="lab_test_ids" context="{'default_appointment': active_id}" domain="[('appointment', '=', active_id)">

My challenge is that I have patient and physician in both views (selection fields) that relate to two other models. I was wondering if I could SET value for a patient field in the parent view and inherit that value to the child view (Lab test). how can I do that?

NOW i use domain to filter through the patient. and the candidate patient is Only one . how can I set this value to the field automatically.

> <field name="patient" domain="[('id', '=', parent.patient)]"

I appreciate your help.

1

1 Answers

0
votes

I'm not sure I 100% fully understand the question but you only have a few options to handle the scenario of copying field data between views.

1. Onchange Field. Create an onchange if they are on the same view. (Don't believe this will work for you.)

lab_test = fields.One2many(...)

@api.onchange('lab_test')
def _onchange_set_lab_test(self):
    self.other_field = self.lab_test

2. Related Field. Setup the child as a related field if it's of the same type:

child = fields.One2many(related='lab_test')

3. Computed Field. Setup the child as a computed field with pulls whatever information you need.

child = fields.One2many(compute='_compute_child_field')