Odoo选择取决于另一个选择

问题描述 投票:0回答:1

我有类似的模特:

class MyDict(models.Model):
_name='my_module.my_dict'

field1=fields.Char()
field2=fields.Char()
field3=fields.Char()

数据看起来像:

obj_1 | attr_1 | val_1
obj_1 | attr_2 | val_1
obj_1 | attr_2 | val_2
obj_2 | attr_1 | val_1
obj_2 | attr_1 | val_2

从另一个模型,我想逐步使用此数据

class NewModel(models.Model):
_name='my_module.new_model'

selection1=field.Selection(selection='_get_selection1')
selection2=field.Selection(selection='_get_selection2')
selection3=field.Selection(selection='_get_selection3')

def _get_selection1(self):
    my_list = []
    selection_list = []
    full_list = self.env['my_module.my_dict'].search([])
    for record in full_list:
       if record.field1 not in my_list:
          my_list.append(record.field1)
       for list_item in my_list:
          selection_list.append((str(list_item), str(list_item)))
    return selection_list

第二个选择需要取决于第一个选择

@api.onchange('selection1')
def _get_selection2(self):
   my_list = []
   selection_list = []
   full_list = self.env['my_module.my_dict'].search([('field1', '=', self.selection1])
   for record in full_list:
      if record.field2 not in my_list:
         my_list.append(record.field2)
   for list_item in my_list:
      selection_list.append((str(list_item), str(list_item)))
   return selection_list

但是我在这里发现错误

File "/opt/odoo13/odoo/odoo/models.py", line 5817, in process
    if res.get('value'):
AttributeError: 'list' object has no attribute 'get'

如何获得selection_list取决于首次选择的内容>

我有类似的模型:类MyDict(models.Model):_name ='my_module.my_dict'field1 = fields.Char()field2 = fields.Char()field3 = fields.Char()数据看起来像:obj_1 | attr_1 | val_1 obj_1 | attr_2 | ...

python odoo selection onchange odoo-13
1个回答
0
投票

看起来唯一的方法是为每个字段制作3个模型并将其绑定到parent_id和child_ids字段中

© www.soinside.com 2019 - 2024. All rights reserved.