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

How to override the onchange_product_tmpl_id with new api?

By
Stefano Del Gobbo
on 1/22/15, 5:52 AM 1,124 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})

1

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 11/18/15, 1:28 PM

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.

0

Temur

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 11/27/15, 9:25 AM

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

2 follower(s)

Stats

Asked: 1/22/15, 5:52 AM
Seen: 1124 times
Last updated: 11/27/15, 9:38 AM