Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6444 Lượt xem

Hello, I have a model which has inherited product.template and in this model I have a One2many field which has an Integer field. The thing is that I have a wizard which checks for this integer records and makes some checking.


At the moment I'm accessing the records like this:

model = self.env['product.template'].search([])
for record in self:
sum_installments = 0
for records in model:

for ids in records.installments_ids:
sum_installments += ids.value

But whenever I call from the wizard it adds up all existing records wile I want to access records for the product I'm.

So how do I get only the records which has the current document I'm in?


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can pass the current record id in the context while opening the wizard as below:

return {
'name': self.name,
'res_model': 'your_wizard_model',
'type': 'ir.actions.act_window',
'context': {'active_id': self.id},
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}

Then you can access the record id from the context as active_id and then later pass the active_id in your product search domain:

active_id = self.env.context.get('active_id')

model = self.env['product.template'].search([('id', '=', active_id)])

Hope this solution will help you

For more details on active_id in odoo refer this link: https://www.youtube.com/watch?v=icl4IEWWmuU

Thank you


Ảnh đại diện
Huỷ bỏ
Tác giả

You are a life saver. Thank You!!

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 23
3782
1
thg 9 21
26891
2
thg 7 20
4072
5
thg 2 19
10327
1
thg 2 24
2758