Odoo Action to return to Tree or Form View, dynamically
top of page
  • Writer's pictureTek Siong, Hock

Odoo Action to return to Tree or Form View, dynamically

Updated: Mar 28, 2021

This Odoo technical development blog is my way to contribute back to the Odoo Community, for all the selfless and great sharing by the community members.


It took me sometimes to figure out how to dynamically view the Tree or Form view from the python method. Here is the code snippet on how to view the vendor bills in tree or form view.


Click "Like" at the bottom of this blog, to motivate us to continue sharing more Odoo tips.


    @api.multi
    def view_vendor_bill(self):
        for operation in self:
            invoices = self.env['account.invoice'].search([
                ('origin', '=', self.booking_no),
                ('type', '=', 'in_invoice'),
            ])

        if len(invoices) > 1:
            #need to have both form and tree view so that can click on the tree to view form
            views = [(self.env.ref('account.invoice_supplier_tree').id, 'tree'), (self.env.ref('account.invoice_supplier_form').id, 'form')]
            return{
                'name': 'Vendor bills',
                'view_type': 'form',
                'view_mode': 'tree,form',
                'view_id': False,
                'res_model': 'account.invoice',
                'views': views,
                'domain': [('id', 'in', invoices.ids)],
                'type': 'ir.actions.act_window',
            }

        else:
            return {
	        'view_type': 'form',
		'view_mode': 'form',
		'res_model': 'account.invoice',
		'res_id': invoices.id or False,   
		'type': 'ir.actions.act_window',
		'target': 'popup',  
            }


Good reference:




3,273 views1 comment
bottom of page