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

Declare onchange method inside old API inherited model

By
Martin Leusch
on 4/11/16, 12:16 PM 524 views

I'm trying to execute a method on user_id change in the sale.order model in Odoo v8, it use osv.osv class.

I create an inherited model with a models.Model class and use the @api.onchange decorator but nothing append.

# -*- coding: utf-8 -*-
from openerp import models, fields, api
from openerp.exceptions import Warning
class Order(models.Model):
    _inherit = 'sale.order'
    @api.onchange('user_id')
    def on_saler_change(self):
        raise Warning(('Something happened.'))
How i suppose to do this?
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 4/12/16, 1:42 AM

Martin,

What you can do is,

  • Inherit form view of sale.order having user_id field and add onchange attribute to it as:

    • <field name="user_id" position="attributes">

      • <attribute name="on_change">on_saler_change(user_id)</attribute>

    • </field>

  • in .py inherit sale.order using old api only and define "on_saler_change(user_id)" in it


Hope it helps!    

0

Jignesh Mehta

--Jignesh Mehta--
2087
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 4/11/16, 11:57 PM

Hello Martin,


If this onchange method is from base module then call super for the same method.


from openerp import models, fields, api, _

from openerp.exceptions import UserError

class Order(models.Model):

    _inherit = 'sale.order'


    @api.onchange('user_id')

    def on_saler_change(self):

        raise UserError(_('Something Happened'))

        return super(Order, self).on_saler_change()


Hope it works for you.


Thanks,

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: 4/11/16, 12:16 PM
Seen: 524 times
Last updated: 4/12/16, 1:42 AM