This question has been flagged
2 Replies
8396 Views

Hello.

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.

Avatar
Discard
Best Answer

Is anyone have an idea ?

Avatar
Discard
Best Answer

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
   my_class()
Avatar
Discard