Skip to Content
Menu
This question has been flagged
3 Replies
6081 Views

Hi,

I'm new to Odoo, and I need to override a existing method.

What i need is to insert new lines on Bill Of Material tree, on changing product template id. 

There are just a method on mrp_bom class, called onchange_product_tmpl_id, so according with what i understood, i need to inherit the mrp_bom class in a new class, and override the onchange_product_tmpl_id method with a new one.

How can I override the method with new api (the old super() in OpenERP) and fire the onchange method when ai change the product template id?

Something like that:

class bom_template(models.Model):

    _inherit = 'mrp.bom'

    @api.onchange

    def _populate_bom_lines(self):

        lines =[]

        for val in self.bom_template: #value on a BOM template that cointain products
        line_item = {
                      'attr1': val.name,
                      'attr2': val.a1,
                      ...                             
                }
        lines += [line_item]
    self.update({'line': lines})

Avatar
Discard
Best Answer

Hello my friend;

here is some useful links:

http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html#api-onchange

https://www.odoo.com/documentation/8.0/reference/orm.html

and here is an example:

Python:

def on_change_prix_id(self, cr, uid, ids,list_price, prix_vente_minimum, context=None): 

if list_price < prix_vente_minimum:

My_error_Msg = 'Attention!! Votre Prix de vente est inférieur au prix de vente minimum'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return True 

else:

return True

XML:

<field name="list_price" on_change="on_change_prix_id(list_price, prix_vente_minimum)">

Best Regards.

Avatar
Discard
Related Posts Replies Views Activity
3
Jun 19
6081
7
Jan 24
13730
1
Jun 15
3467
3
Nov 24
13055
2
Aug 23
1490