top of page

Odoo Action to return to Tree or Form View, dynamically

  • Writer: Tek Siong, Hock
    Tek Siong, Hock
  • Mar 15, 2020
  • 1 min read

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:




Recent Posts

See All

1 Comment


browseinfo.in
Jul 03, 2020

Thanks for sharing this blog on odoo. It's useful information, keep sharing.

Like

Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page