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

I want to pass an ID to a transient wizard model.

This is the code to launch the wizard-popup:


# -*- coding: utf-8 -*-

from openerp import models, fields, api

class StockPicking(models.Model):

_inherit = "stock.picking"

@api.multi

def view_tree_label_picking(self):

return {

'type': 'ir.actions.act_window',

'name': 'view_tree_label_picking',

'view_type': 'tree',

'view_mode': 'tree',

'res_model': 'label.picking', 

'target': 'new',

}

How do I pass the current stock_picking ID to the transient model?

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

you can use this,

see this link: https://github.com/odoo/odoo/blob/9.0/addons/account/models/account_bank_statement.py#L213

return {

'type': 'ir.actions.act_window',

'name': 'view_tree_label_picking',

'view_type': 'tree',

'view_mode': 'tree',

'res_model': 'label.picking', 

'context': {},

'target': 'new',

}

 

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

in context you can pass the current object id or in context itself have the active_id and active_model in pop wizard

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

Could you please further elaborate? Is that following new or old API? Thanks

in new api you can access active id directly self._context.get('active_id') and in old api you can access directly context.get('active_id') where context is the function parameter.

Tác giả Câu trả lời hay nhất

[UPDATE] Despite some colleagues have tried to answer I am still not being able to move the ID from the form to the wizard transient model. I am missing something, thanks anyway for your help. Anyone willing to give a more detailed solution please do, as this not solved yet.

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

hi, 

Reference to this post: 

https://www.odoo.com/es_ES/forum/help-1/question/developing-a-new-popup-in-stock-picking-basic-doubts-about-how-to-generate-the-popup-97625

with that question I have also fought x-D with this code:

   context.update({ 'tipo_entrega' : 'ok_con_incidencias', 'delivery_line_id': value that you want, }) 
you can pass the info in the context to popup because you add param 'context':
context ( see -> #python desde donde lanza la acción del botón).

And you obtain the pass value in this line:
record_id = context.get('delivery_line_id') ( see -> #modelo temporal para popup.)

May the Force be with you !!!

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

Thanks, just to gain a better understanding on how development works in Odoo, is the way you suggest following the new or the old API? I am sometimes puzzled on how both APIs are mixed together.

If I'm honest I also do blends between the new and the old api api ... and I venture to say that most people do ... :-) I think the balance is the best way ...

Tác giả

I get context is not defined.

Tác giả

New API is reasonablily well documented, old one is not. It is a big issue if you start doing things without fully understanding what you do.

I get context is not defined error?. Try to add this: if context is None: context = {} ....

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 16
8795
3
thg 6 19
5361
1
thg 3 15
6980
3
thg 2 24
12756
2
thg 8 22
9083