Reputation: 1043
I have created wizard. And on button click I want to open form view with specific model record id.
@api.multi
def create_order(self):
view = self.env.ref('purchase.purchase_order_form')
context = self.env.context
return {
'name':'Name',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'views': [(view.id, 'form')],
'view_id': view.id,
'res_id': 264,
'context': context,
}
The problem is that on button click I can't open other form view.
If I add 'target': 'new', then on button click on popup window I open form which I need:
@api.multi
def create_order(self):
view = self.env.ref('purchase.purchase_order_form')
context = self.env.context
return {
'name':'Name',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'views': [(view.id, 'form')],
'view_id': view.id,
'target': 'new',
'res_id': 264,
'context': context,
}
The problem is that on button click I need to open specific form but like popup window. I tried set 'target': 'inline' or 'target': 'current' but nothing happens.
Upvotes: 1
Views: 4616
Reputation: 1389
SEE AT THE END OF THE RESPONSE FOR A SIMPLER SOLUTION
I had the same problem but I was able to resolve it. I must say that I am using a old OpenERP version (5.0.14), so maybe it does not work with you.
model_obj = self.pool.get('ir.model.data')
res_id = model_obj.get_object_reference(cursor, uid,
'your_model',
'your_view_id_ref_defined_in_xml')[1]
return {
'name': 'View name, anything you want',
'type': 'ir.actions.act_window',
'res_model': 'view_model',
'domain': "[('id', 'in', {})]".format(ids_to_show),
'view_type': 'form',
'view_id': (res_id, 'View'),
}
Using the question example it will be:
model_obj = self.pool.get('ir.model.data')
res_id = model_obj.get_object_reference(cursor, uid,
'purchase',
'purchase_order_form')[1]
return {
'name': 'View name, anything you want',
'type': 'ir.actions.act_window',
'res_model': 'purchase.order',
'view_type': 'form',
'view_id': (res_id, 'View'),
}
Hope it helps!
SIMPLER SOLUTION
Another, maybe simpler and cleaner solution is to set the view_id to False and set the view that you want to load in the context. You can specify what view you will load for the tree part with 'tree_view_ref' and the form part with 'form_view_ref'.
Here is an example loading a view called custom_stock_tree_view and custom_stock_form_view defined in a module called custom_stock
return {
'name': 'Custom Stocks',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.move',
'view_id': False,
'type': 'ir.actions.act_window',
'context': {
'tree_view_ref':
'custom_stock.custom_stock_tree_view',
'form_view_ref':
'custom_stock.custom_stock_form_view'
}
}
Please, note that the view_id is set to False. Otherwise it will not load the desired view (Thanks to Joan M. Grande, who saw this).
Upvotes: 0
Reputation: 2145
What model/record is this being called from? For example, are you adding this to a Sales Order or some other model's form?
If so, you may need to set include the Source Model, such as:
'src_model': 'sale.order',
In the documentation, this is used for launching wizards and may be needed for redirecting the model.
Upvotes: 0
Reputation: 1675
I think the problem will resides on your param res_id, this is not needed actually. its only return the record of res_id if exists. Any way I give you an valid example. so please try:
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}
Upvotes: 1