我正在研究audit
模块上的工作流程,我将工作流程添加到视图中,如下所示:
audit.xml
中的:
<header>
<button name="button_close" string="Close" states="opened" icon="gtk-jump-to" type="object"/>
<button name="button_open" string="Open" states="draft" type="object"/>
<button name="button_validate" string="Validate" states="done" icon="gtk-jump-to" type="object"/>
<field name="state" widget="statusbar" select="1" readonly="1" clickable="True"/>
在audit.py
我有:
'state': fields.selection(
[
('draft', 'Draft'),
('opened', 'Opened'),
('done', 'Closed'),
('validated','Validated')
],
'State',
),
_defaults = {
'state': 'draft'
}
def button_open(self, cr, uid, ids, context=None):
self.message_post(cr, uid, ids, _("Audit created"), context=context)
return self.write(cr, uid, ids, {'state': 'opened'})
def button_close(self, cr, uid, ids, context=None):
"""When Audit is closed, post a message to followers' chatter."""
self.message_post(cr, uid, ids, _("Audit closed"), context=context)
return self.write(cr, uid, ids, {'state': 'done'})
def button_validate(self, cr, uid, ids, context=None):
"""When Audit is validated, post a message to followers' chatter."""
self.message_post(cr, uid, ids, _("Audit validated"), context=context)
return self.write(cr, uid, ids, {'state': 'validated'})
我希望状态保持在工作流程中,但是当我保存新记录时,状态会自动更改为'validated'
。
答案 0 :(得分:0)
以下是覆盖写入的示例代码:
def write(self, cr, uid, ids, vals, context=None):
## do your code here
return super(yourclassname, self).write(cr, uid, ids, vals, context=context)
答案 1 :(得分:0)
试试这个:
def create(self, cr, uid, ids, vals, context=None):
# write your logic here
return super(my_model_name, self).create(cr, uid, ids, {'state':'validated'}, context=context)