简体   繁体   中英

How to export data from any model without adding a new tree view and menuitem? How to show the default tree view of any model?

Normally, if you want to export data to a CSV withing the Odoo interface, you will need to follow these steps:

  1. Go to the "tree" (or called "list" in new versions) view of the model you want to export some data
  2. Select some records to export them to the csv file
  3. More > Export
  4. Select the fields to export

And that's it. This is OK for the models that already have a tree view accessible from a menuitem. But if you want to export data from a model which don't have view or menuitem to access to the view you can't export the records unless you create the menuitem + action + view.

I know that the tree view of any model can be shown even if the form was not created by hand. Odoo creates a default form for any model if it is not create by the programmer.

So, my questions are:

  • How to export data from any model without adding a new tree view and menuitem and action?
  • How to show the default tree view of any model without direct access (menuitem)?

I am afraid the only way is to create a button in the ir.model form view in order to show the tree view for that model. Any other idea? Is there already a way or a module to do this?

I am wondering if there is some trick using some parameters in the url, the address uses the menuitem id and the action id:

http://localhost:8069/web?debug=#view_type=list&model=ir.ui.view&menu_id=41&action=25

And I know I can export data related to some model browsing in the export popup, but you can't export all the records of the other model, only the records related to the current model.

Well I did not find any fast trick. But the best approach is to create a custom module in order to add a button to the ir.model form and return the default tree view like this:

@api.multi
def show_tree_view(self):
    self.ensure_one()
    return {
        'name': _("Export data"),
        'view_type': 'form',
        'view_mode': 'tree,form',
        'res_model': self.model,
        'view_id': False,
        'type': 'ir.actions.act_window',
        'context': self.env.context,
    }

And that's it, the button will show any tree view where the user can select the records to export :)

The code of the view would be:

<record id="view_model_form_inherit" model="ir.ui.view">
    <field name="model">ir.model</field>
    <field name="inherit_id" ref="base.view_model_form" />
    <field name="arch" type="xml">
        <field name="name" position="before">
            <button type="object" name="show_tree_view" string="Show tree view" />
        </field>
    </field>
</record>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM