Skip to Content
Menu
This question has been flagged
2 Replies
5575 Views

Hello,

I have a python function that returns a treeview but it's not a normal treeview, I can't create or select some records.

How to return a normal treeview ?


Python function :

@api.multi

@api.model

def chargement_ratio(self):

        productRatio = self.env['miadi.poidsconditionnement']

        conditionnements = self._cr.execute("SELECT id FROM miadi_packaging")

        query_cond = self.env.cr.dictfetchall()

        produits = self._cr.execute("SELECT id FROM product_product")

        query_prod = self.env.cr.dictfetchall()

        for conditionnements in query_cond:

                nom_conditionnement = conditionnements['id']

                for produits in query_prod:

                        product = produits['id']

                        if_exist = self._cr.execute("SELECT * FROM miadi_poidsConditionnement WHERE conditionnement_id=%s AND produit_id=%s", (nom_conditionnement, product))

                        exist = self.env.cr.dictfetchall()

                        if not exist:

                                Ratio = productRatio.create({'conditionnement_id': nom_conditionnement, 'produit_id': product})

        return {'name': _('Weight/number Ratio'), 'view_type': 'tree', 'view_mode': 'tree', 'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id, 'res_model': 'miadi.poidsconditionnement', 'type': 'ir.actions.act_window', 'target': 'current',}


The treeview returned by the function : https://www.hostingpics.net/viewer.php?id=651454Capturetreeview3.png
What I want :https://www.hostingpics.net/viewer.php?id=947270Capturetreeview2.png


I'm on Odoo 10


Thanks for answers

Avatar
Discard
Best Answer

Dear Miadi,

Try to change view_type: form  instead of tree

return {'name': _('Weight/number Ratio'), 'view_type': 'form', 'view_mode': 'tree', 'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id, 'res_model': 'miadi.poidsconditionnement', 'type': 'ir.actions.act_window', 'target': 'current',}




I hope I helped you...
Avatar
Discard

Please Try it...

Author

Sorry I ate. Thank you very much it works !

Best Answer

HI,

For the menu first you have to define both the form and tree view. Then from the python function you can return like this with view_type as the form.

return {
'domain': [('id', 'in', new_invoice.values())],
'name': 'Invoices',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'view_id': False,
'views': [(self.env.ref('account.invoice_tree').id, 'tree'), (self.env.ref('account.invoice_form').id, 'form')],
'context': "{'type':'out_invoice'}",
'type': 'ir.actions.act_window'
}


Avatar
Discard