Odoo Help

0

[V9] How to Inherit write function

9.0
By
Andreas
on 10/18/15, 10:09 AM 1,348 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. 

Did you get it?

Akhil P Sivan
on 10/20/15, 1:55 AM

Yup. Thanks Akhil P Sivan

Andreas
on 10/25/15, 1:38 AM
1
Akhil P Sivan
On 10/19/15, 6:20 AM

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)


0
Yogesh
On 10/18/15, 2:06 PM

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)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 10/18/15, 10:09 AM
Seen: 1348 times
Last updated: 10/25/15, 1:38 AM