Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
7127 Visualizações

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
Cancelar
Melhor resposta

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
Cancelar
Autor

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

Publicações relacionadas Respostas Visualizações Atividade
1
ago. 19
4196
1
jan. 16
8741
3
mai. 25
1275
1
abr. 25
3145
3
nov. 24
8011