1

我在 tryton 中有 2 个模块,第一个是employee,第二个是pointage. 我正在尝试添加一个允许我选择pointage.

为此,我们必须创建一个元组列表,pointagedef = [('', '')] 现在我们已经填写了它,但问题是我找不到任何文档来了解如何做到这一点

pointage= fields.Selection(pointagedef, 'grh.pointage')   

我正在尝试做类似的事情:

for pointage in pointages:
    pointagedef.append((pointage, pointage))
4

1 回答 1

4

You just have to declare a list of two value tuples with the values. Something like:

colors = fields.Selection([
   ('red', 'Red'),
   ('green', 'Green'),
   ('blue', 'Blue'),
], 'Colors')

The first value will be the internal one, and that will be stored on the database. The second value is the value shown on the client and by default is translatable.

You can also pass a function name, that returns the list of two value tupple. For example:

colors = fields.Selection('get_colors', 'Colors')

@classmethod
def get_colors(cls):
   #You can access the pool here. 
   User = Pool.get('res.user')
   users = User.search([])
   ret = []
   for user in users:
      if user.email:
         ret.append(user.email, user.name)
   return ret

Also if you want to access a single table, you can use a Many2One field, adding widget="selection" on view definition, so the client will render a selection widget instead of the default one, and preload all the records of the table to the selection.

于 2014-08-01T13:28:42.257 回答