Skip to Content
Menú
This question has been flagged
1 Respondre
12575 Vistes

hello 

i want to know what is active id and what is the use of active id 


how can i print the active id 

i add one many 2 one field res.partner

and now i add smart button which give me the sale order which res.partner i selected.


my problem is it will give me the all of the sale order but i want only sale order which res.partner i selected.

any one can help me!

thank you in advance


Avatar
Descartar
Best Answer

Hi,

active_id is the current record's id. You can get the active_id from the context as this:
active_id =  self.env.context.get('active_id')

The use cases are explained in this video in detail Active Id In Odoo Development


And for getting sale orders of the partner selected try this solution:

In your python file:


partner_id = fields.Many2one('res.partner', string='Customer')

def get_sale_orders(self):
return {
'name': _('Sale Orders'),
'type'
: 'ir.actions.act_window',
'res_model'
: 'sale.order',
'view_mode'
: 'kanban,tree,form',
'domain'
: [('partner_id', '=', self.partner_id.id)],
}

In your xml file define the button(type=object) and partner_id field:

Pass the domain: 

'domain': [('partner_id', '=', self.partner_id.id)] , while returning from the button function

Thank you

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
d’oct. 22
3068
3
d’oct. 22
11875
1
de des. 23
1415
0
de set. 22
2176
0
d’abr. 22
2627