Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
7132 Vistas

Hello community,


I'm trying to give a specific record to my new view that I call from an action.

I know how I can give the active_id and use that in the new model field as a default value.


I have a field as a Many2one of product.product. I want to give it a context from the 'product.template' view, but active_id should not be the 'product.template' ID, it should be the 'product.product' ID from that Base Product.


Something like this:

<field name="context">{'search_default_product_id': product_variant_id.id, 'default_product_id': product_variant_id.id}</field>

Thanks,





Avatar
Descartar
Mejor respuesta

Hi,

Can you achieve it using the the default_get method ? Super the default get method of the corresponding model and inside it, check whether you have particular value inside the context, if so, set the default value from there.

See a sample from the MRP module:

@api.model
def default_get(self, fields_list):
defaults = super(StockMove, self).default_get(fields_list)
if self.env.context.get('default_raw_material_production_id'):
production_id = self.env['mrp.production'].browse(self.env.context['default_raw_material_production_id'])
if production_id.state == 'done':
defaults['state'] = 'done'
defaults['product_uom_qty'] = 0.0
defaults['additional'] = True
return defaults

For more: Default Get Function: Set Default Values For Fields In Odoo


Thanks

Avatar
Descartar
Autor

thank you, I have fixed it with your example =)

Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 19
4198
1
ene 16
8749
3
may 25
1280
1
abr 25
3145
3
nov 24
8013