Skip to Content
Menu
This question has been flagged
9 Replies
15757 Views

Hello,

In a personal module, I have a model and when I click on a record in the treeview, I have the form view to edit this record.

How to display another form view (like a pivot view or other) ?

Thanks for answers

Avatar
Discard

Hello Miadi,

Are you trying to add a pivot view for your model?

Author

When I click on a menuitem, I have a treeview with some records and when I click on a record, I want to show a pivot view.

Author

Instead of the form view that is display by default

I think what you are trying to achieve is making a pivot view for a single record instead of all the records of the model. As per my understanding this is not possible.

Author

Please check what I post in an answer and tell me if it's possible please

Author Best Answer

Or, I found another solution : it's to add a button on each record to display the pivot view. but it's gives me this error :

AttributeError: type object 'miadi.tarifs' has no attribute 'display_pivot_view'


Here are my codes :

class miadi_tarifs(models.Model):
    _name = 'miadi.tarifs'
    
    code = fields.Char(string='Code', default='', required=True)
    libelle = fields.Char(string='Libellé', default='', required=True)
    remise = fields.Float(string='Remise', digits=(5,2), default=0)
    
    _sql_constraints = [
    ('uniq_id', 'unique(code)', 'A pricelist already exists with this code. It must be unique !'),
    ]

@api.multi
    def display_pivot_view(self):
        tarif = self.code
        return {'name': _('Pivot Lines'), 'view_type': 'form', 'view_mode': 'pivot,tree', 'view_id': False, 'views': [(self.env.ref('miadi_packaging.miadi_lignestarifs_pivot').id or False, 'pivot'), (self.env.ref('miadi_packaging.miadi_lignestarifs_tree').id or False, 'tree')], 'res_model': 'miadi.lignestarifs', 'type': 'ir.actions.act_window', 'target': 'current', 'domain': [('code_tarif', '=', tarif),]} #Retourne la vue tableau, la treeview et la vue formulaire
class miadi_lignesTarifs(models.Model):
    _name = 'miadi.lignestarifs'
    
    code_tarif = fields.Many2one('miadi.tarifs', 'Price Code', default='', required=True, ondelete='cascade')
    numero_ordre = fields.Integer('Order number')
    produit_id = fields.Many2one('product.product', 'Product', required=True, ondelete='cascade')
    conditionnement_id = fields.Many2one('miadi.packaging', 'Packaging', required=True, ondelete='cascade')
    prix_unitaire = fields.Float('Unit Price', default=0)
<record id="miadi_tarifs_tree" model="ir.ui.view">
            <field name="name">miadi.tarifs.tree</field>
            <field name="model">miadi.tarifs</field>
            <field name="arch" type="xml">
                <tree string="Prices" >
                    <field name="code" />
                    <field name="libelle" />
                    <field name="remise" />
                    <button name="display_pivot_view" type="object" string="Table view" class="oe_highlight" />
                </tree>
            </field>
        </record>

How to fix the problem ?

Avatar
Discard

You give your button action in "wizard.pivot.view" and button in "miadi.tarifs"

also display button in form view not tree

Author

Yes I saw the error just before to see your comment.

I had a button in each record in the treeview because I want on click on the button to display the pivot view for this record

Author

Can you help me ?

With the code in the answer, when I click oon the button for a record, it display the pivot form but with all records (all prices) but I want only the pivot view for the record where I click on the button. I don't know if you understand me

Pivot view is usually used for analysing all datas. There is no point in showing a single record.

Anyway you can achieve that by passing required filters

Author

It worked in a post where you answered yesterday. So, why here it doesn't work ?

I told you whats the error.

Author

Yesterday, in this post (mine) : https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-display-a-pivot-view-after-a-form-view-depending-of-a-field-120339

You gave me a solution to have the pivot view depending of one field and here, it's the same but it doesn't work...

The difference is, instead of open a wizard with a field, I add a button directly in the record in the table where the field were selected.

Author

I found the solution ! Thank you for your help

Best Answer

In the action

 <!-- action --> 
    <record id="yourid" model="ir.actions.act_window">
    <field name="name">....</field>
    <field name="res_model">yourmodel</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>
I just know "view_type" which is the type of view when I click on a record
Avatar
Discard
Author

Hi, I tried to put "pivot" instead of "form" in the view_type and it gives me : ParseError: "Wrong value for ir.actions.act_window.view_type: 'pivot'"

Related Posts Replies Views Activity
2
Jun 17
3278
1
Sep 23
3581
2
May 21
2983
2
Jun 22
2746
0
Sep 21
1250