跳至内容
菜单
此问题已终结
1 回复
12737 查看

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


形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
10月 22
3191
3
10月 22
12130
1
12月 23
1490
0
9月 22
2277
0
4月 22
2730