Skip to Content
Menu
This question has been flagged

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
Discard
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
Discard
Related Posts Replies Views Activity
2
Oct 22
1922
3
Oct 22
9103
1
Dec 23
593
0
Sep 22
1318
0
Apr 22
1633