Odoo Help


Create popup on onchange + return new field value on parent view

on 5/5/13, 3:43 PM 4,181 views


I am French, I hope you understand :)

I'm trying to develop a module that creates a relationship between products. A product can be linked to several other products: they are identical but are occasions.

So there is a one2many relation (child_ids, one product for several occasions) and another many2one relation (parent_id, many opportunities for one parent). This is equivalent to reproduce the same relation between a partner (res.partner) and contacts (res.partner too).

When a user creates a sale order line (sale.order.line) in an order (sale.order), he must select the a product. If the selected product has occasion product(s), so I want to warn and allow him to select one.

It is necessary to overload the product_id_change() method (onchange on the product_id field defined on parent class) and search for existing attached product(s) (occasions).

I must to display the list of attached product and allow user to replace the product in the sale order line.

My questions:

  1. Should I force a new search (like "search more ..." link) from the product_id_change() function?
  2. Should I use a wizard (osv.memory) to open the popup and show him the available opportunities?
  3. If so, how can I update the parent form (sale.order.line) to change the value of product_id field?
  4. If not, are there any other way to achieve this?

Thank you for your help.



--Borni DHIFI--
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 


Skype : dhifi.borni

On 5/10/13, 6:47 AM

you can add another field 'product_child_id' in sale.order.line .

'product_child_id': fields.many2one('product.product', 'Product Child',),

add the field in view sale.order . if user selected a product it load the list product_child_id of the product.

must be redefined product_id_change() function to load product_child_ids for this product .something like that:

class my_class(osv.osv):
_inherit = 'sale.order.line' 
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False,
            fiscal_position=False, flag=False, context=None):

    res = super(my_class, self).product_id_change(cr, uid, ids, pricelist,
            product, qty=0,uom=False, qty_uos=0, uos=False, name='', 
            partner_id=False,lang=False, update_tax=True, date_order=False,
            packaging=False, fiscal_position=False, flag=False, context=None)

    product_pool = self.pool.get('product.product')
    product_browse= product_pool.browse(cr, uid, product)
    res['value']['product_child_id'] = product_browse.product_child_ids

    return res
On 5/10/13, 5:34 AM

Is anyone have an idea ?

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/5/13, 3:43 PM
Seen: 4181 times
Last updated: 3/16/15, 8:10 AM