有没有办法使用 Python 更改选择字段值,但我没有找到任何可以使用的文档。 状态字段是描述治疗状态的字段
我想做这样的事情:
state=fields.Selection([
('stopped', 'Stopped'),
('wait', 'Wait'),
('finished', 'finished'),
], 'State', readonly=True)
def changeselectionvalue(self,state)
self.state=state #something to do this
请帮助我,我是 Tryton 的新用户
最佳答案
只需使用写入 API:
records = Model.search([]) #Get all the records you wan to write.
Model.write(records, {'state': 'new_state'})
或者 ActiveRecord 模式:
self.state = 'new_state'
self.save()
“新状态”必须是选择的内部值之一。
当您必须更新一组记录中的多个记录时,建议使用第一个。
如果您是 Workflow 类的模型子类,建议使用 @Workflow.transition(new_state) 装饰器来更改记录的状态,因为它仅更新转换有效的记录。
关于python - 如何在 Tryton 上使用 Python 更改选择的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25217954/