Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1857 Переглядів

i want write a script that when i select table name the related column name of the table is show in the drop down in odoo.. here is my code..

table_name = fields.Selection( [('res_partner', 'Contacts'), ('res_company', 'Companies')], string='Table Name', tracking=True, required=True)

column_name = fields.Selection([], string='Column Name')

@api.model
def get_column_names(self, table_name):

query = """
       SELECT column_name
       FROM information_schema.columns
       WHERE table_name = %s
   """
self.env.cr.execute(query, [table_name])
result = self.env.cr.fetchall()
return [(row[0], row[0]) for row in result]


@api.onchange('table_name')
def onchange_table_name(self):
if self.table_name:
    column_names = self.get_column_names(self.table_name)
    columnlist = [(name[0], name[1]) for name in column_names]
    self.column_name.selection = columnlist
    

i am getting following error..

self.column_name.selection = [] AttributeError: 'bool' object has no attribute 'selection'

how to solve this error..

Аватар
Відмінити
Найкраща відповідь

Hi,

You can try using Reference Field in Odoo, which helps you to show data from the records based on model selection.

Sample:

action = fields.Reference(selection=[('ir.actions.report', 'ir.actions.report'),
('ir.actions.act_window', 'ir.actions.act_window'),
('ir.actions.act_url', 'ir.actions.act_url'),
('ir.actions.server', 'ir.actions.server'),
('ir.actions.client', 'ir.actions.client')])


See: Working of reference field in Odoo


Thanks

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
трав. 24
1024
1
черв. 23
1479
1
трав. 23
4747
3
лют. 23
4501
2
бер. 15
5153