Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
7123 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Related Posts Odpovědi Zobrazení Aktivita
1
srp 19
4196
1
led 16
8739
3
kvě 25
1273
1
dub 25
3141
3
lis 24
8007