1

I have 2 modules in tryton the first is employee and the second is pointage. I am trying t add a Selection field that allow me to select the pointage.

To do that we have to create a list of tuple pointagedef = [('', '')] now we have fill it but the problem that i can't find any documentation to understand how to do it

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

i am trying to do something like:

for pointage in pointages:
    pointagedef.append((pointage, pointage))
gasroot
  • 515
  • 3
  • 15

1 Answers1

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.

pokoli
  • 1,045
  • 7
  • 15
  • 1
    no this is not what i am looking for i am lookin to fill the selection field from database – gasroot Aug 01 '14 at 13:37
  • So in the get_colors method, just access the database. I edited the response to shown an example. – pokoli Aug 01 '14 at 14:14