1

Is there a way to change selection field value using Python and I didn't find any documentation to use . The state field is a field that describe a treatment state

I wish to do something like :

state=fields.Selection([
        ('stopped', 'Stopped'),
        ('wait', 'Wait'),
        ('finished', 'finished'),
        ], 'State', readonly=True)

def changeselectionvalue(self,state)
    self.state=state #something to do this

Help me please I am a new user of a Tryton

remudada
  • 3,751
  • 2
  • 33
  • 60

1 Answers1

1

Just use the write API:

records = Model.search([]) #Get all the records you wan to write. 
Model.write(records, {'state': 'new_state'})

Or the ActiveRecord pattern:

self.state = 'new_state'
self.save()

'new state' must be one of the internal values of the selection.

The first is recomended when you have to update more than one record in a bunch.

If you're model subclasses the Workflow class, It's recommended to use the @Workflow.transition(new_state) decorator in order to change the state of the records, as it only updates the records for which the transition is valid.

pokoli
  • 1,045
  • 7
  • 15