if i have model project that have one or more from model unit , then i have another model that i want to select project then on change the project want to populate the units according to project selection
example
have project 1 have units 1,2 ,3
project 2 have units 1,4,5
when select project want to populate the units 1,2,3 if changed to project 2 populate the units 1,4,5
i have written my own code to get the list of related units, just want to know how i can set this list to the units
here is the code
class rsproject(models.Model): _name = 'rs.project' units = fields.One2many('rs.unit','name',string ='Units', ondelete='cascade') class rs_unit(models.Model): _name="rs.unit" project = fields.Many2one('rs.project', ondelete='cascade', string="Project", required=True) class rsreservation(models.Model): _name = 'rs.reservation' project = fields.Many2one('rs.project', ondelete='cascade', string="Project", required=True) unit = fields.Many2one('rs.unit', ondeletel='cascade', string="Unit Number", required=True) @api.one @api.onchange('project') def on_change_project(self): units_obj = self.pool.get('rs.unit') project_id = self.project.id #get units list according to selected project unit_list = units_obj.search(self._cr,self._uid,[('id','=',project_id)]) # what is the correct syntax to set the unit field with unit_list
please include view file...