跳至内容
菜单
此问题已终结
2 回复
9428 查看

I'm write code for python to inherit res.partner.

This code is when user click save button to update record, it will set state into draft (state = 'draft') if state = approved.

Any idea or clue to write this code?

class res_partner(models.Model):

_inherit = 'res.partner'

print "write procedure inherit awal"

STATE_SELECTION = [
('draft', 'Draft'),
('approved', 'Approved'),

]
state = fields.Selection(STATE_SELECTION, 'Status', readonly=True,
help="Draft Record "
"Approved Record. ",
select=True,default='draft')

def write(self, vals):
if vals.get('state'):
if vals.get('state')=='approved':
state = 'draft'
return super(res_partner, self).write(vals)


it doesn't work.

Thanks. 

形象
丢弃

Did you get it?

编写者

Yup. Thanks Akhil P Sivan

最佳答案

Hi,

You may try like this to override the write():

    @api.multi
def write(self, vals):

if self.state == 'approved':
vals.update({'state':'draft'})

return super(res_partner, self).write(vals)


形象
丢弃
最佳答案

You have to update vals dictionary with new values before calling super.

def write(self, vals):
if vals.get('state')=='approved':
vals.update({'state' : 'draft'})
return super(res_partner, self).write(vals)
形象
丢弃
相关帖文 回复 查看 活动
1
12月 18
6770
1
1月 17
4640
1
4月 19
4673
5
6月 18
8420
1
3月 18
4269