Odoo Help

Welcome!

This community 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.

0

[V9] How to Inherit write function

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

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

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)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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