Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
6737 Vizualizări

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?
Imagine profil
Abandonează
Cel mai bun răspuns

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!    

Imagine profil
Abandonează
Cel mai bun răspuns

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,

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
7
oct. 17
12895
3
mar. 15
3885
0
nov. 16
3993
4
ian. 16
10298
2
mar. 15
4907