Skip to Content
Menu
This question has been flagged
2 Replies
8391 Views

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. 

Avatar
Discard

Did you get it?

Author

Yup. Thanks Akhil P Sivan

Best Answer

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)


Avatar
Discard
Best Answer

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)
Avatar
Discard
Related Posts Replies Views Activity
1
Dec 18
5587
1
Jan 17
3721
1
Apr 19
3657
5
Jun 18
7467
1
Mar 18
3536