Community mailing list archives

community@mail.odoo.com

Avatar

dynamic domain not set on edit

by
Ronny Houben
- 2017年12月01日 03时49分23秒

Dear all,

 

For a user to find a particular product, he/she is able to fin dit by narrowing the selection on various properties.

 

So, for instance when a brand is selected, only the available types, kind, diameter and product of that brand are available.

Or when a diameter is selected, only the brands, types, kinds and product which have a product with that diameter are shown.

And so on and so on…

When a product is selected, no other choices are available anymore.

 

@api.onchange('product_id_right')
def onchange_productselection(self):
   
if self.product_id_right:
       
self.product_brand_id = \
           
self.product_id_right.product_brand_id
       
self.product_type_id = \
           
self.product_id_right.product_type_id
       
self.product_glasseskind_id = \
           
self.product_id_right.product_glasseskind_id
       
self.product_diameter_id = \
           
self.product_id_right.product_diameter_id
       
self.product_price_right = self.with_context(
           
pricelist=self.pricelist_id.id).product_id_right.price

 

@api.onchange('product_brand_id', 'product_type_id',
             
'product_glasseskind_id', 'product_diameter_id')
def onchange_selectionfields(self):
    crit = []
    crit.append((
'product_tmpl_id.product_kind', '=', 'G'))

   
if self.product_brand_id:
        crit.append((
'product_tmpl_id.product_brand_id', '=',
                    
self.product_brand_id.id))

   
if self.product_type_id:
        crit.append((
'product_tmpl_id.product_type_id', '=',
                    
self.product_type_id.id))

   
if self.product_glasseskind_id:
        crit.append((
'product_tmpl_id.product_glasseskind_id', '=',
                    
self.product_glasseskind_id.id))

   
if self.product_diameter_id:
        crit.append((
'product_tmpl_id.product_diameter_id', '=',
                    
self.product_diameter_id.id))

    product_ids =
self.env['product.product'].search(crit)
    product_type_ids = product_ids.mapped(
'product_type_id.id')
    product_brand_ids = product_ids.mapped(
'product_brand_id.id')
    product_diameter_ids = product_ids.mapped(
'product_diameter_id.id')
    product_glasseskind_ids = product_ids.mapped(
       
'product_glasseskind_id.id')

   
return {'domain': {
       
'product_type_id': [
            (
'id', 'in', product_type_ids)],
       
'product_brand_id': [
            (
'id', 'in', product_brand_ids)],
       
'product_diameter_id': [
            (
'id', 'in', product_diameter_ids)],
       
'product_glasseskind_id': [
            (
'id', 'in', product_glasseskind_ids)],
       
'product_id_right': [
            (
'id', 'in', product_ids.ids)]
    }}

 

 

This works perfect in create mode.

Problem is when editing, the values are filled in and displayed, but the domains are not set since the onchange is not triggered.

 

  • How can I set the correct domains after clicking on edit?

Regards,

Ronny Houben - Apertoso business ICT

http://www.apertoso.be/

Guido Gezellelaan 16 - B-9800 Deinze - Belgium

Phone: +32 9 381 64 50 
Mobile: +32 477 43 78 02