Skip to Content
Menu
This question has been flagged
3 Replies
5268 Views

Hello,

I use Odoo 14 Enterprise. From a wizard form, I want to return a form view with record list into domain.

If i use tree view, this action is great. But, i want directly show to result into form view.

Can you help me ?

My code :

return {
    'type': 'ir.actions.act_window',
    'views': [(False, 'tree'), (False, 'form')],
    'res_model': 'annual.control.base',
    'domain': [('id', 'in', [174, 175])],
    'target': 'current',
    # 'context': ctx,
}

Thanks

Avatar
Discard
Best Answer

To return a form view with a specific record list, you can use the 'view_mode' attribute and set it to 'form' instead of 'tree,form', also you can use 'res_id' attribute and set it to the id of the record you want to show in the form view.
Here is an example of how you can modify your code:

This way, when the wizard is closed, it will return a form view of the record with the id 174. If you want to show multiple records, you can use 'res_ids' attribute and set it to a list of ids, for example :

This way, when the wizard is closed, it will return a form view of the records with ids 174 and 175.

Please note that this will only work if the view type is form, otherwise it will not show anything.

Avatar
Discard
Author

Hello,
Thanks for your answer but it doesn't work for me. On your side, does it work?
I wrote exactly your code and I can't display a sequence of form views without going through a list view

Author

'res_ids' doen't exists on model 'ir.actions.act_window'

Best Answer

Hello buddy, I have the same issue too. I've tried all the methods mentioned above, but I got the wrong results. Do you have any good solutions now? Thanks.

Avatar
Discard
Best Answer

In Odoo 14 Enterprise, you can return a form view with a record list in the domain using the action attribute of the wizard's return statement. The action attribute should be set to a dictionary that specifies the view type, view_mode, and domain.

Here's an example of how you can do this in your wizard:

Copy codeclass MyWizard(models.TransientModel):
    _name = 'my_wizard'
    # fields and methods

    def action_show_records(self):
        domain = [('field_name', '=', self.field_value)]
        action = {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my_model',
            'target': 'current',
            'domain': domain,
        }
        return action

In this example, the action_show_records method returns an action that opens a form view of the my_model model, filtered by the domain specified in the domain attribute. The target attribute set to 'current' will open the form view in the current window, replacing the wizard. You can also set the target attribute to 'new' if you want to open the form view in a new window.

Note that, in this example, the form view will show only the first record that matches the domain, but if you want to show all the records that match the domain, you can set the view_mode to 'tree,form' and set 'view_id' to formview_id of that specific model.

Avatar
Discard
Author

Hello,
Thanks for your answer but it doesn't work for me. On your side, does it work?
I wrote exactly your code and I can't display a sequence of form views without going through a list view ? The domain is not taken into account when I want to display a form view

Related Posts Replies Views Activity
1
Mar 21
3695
0
Jul 25
183
1
Jun 25
906
0
May 25
967
2
Apr 25
2987