Odoo - OpenERP - How to add a new menu item (All Project attachment files) and show all files attached to all projects?

What I really miss is an overview of all files that are attached to all projects.

In essence a way to view all files stored for any project in a list.

Support
Support
5000
| 2 1 2
Asked on 8/14/15, 2:37 PM
0
vote
4180 Views

tested on v7...

there are two ways to achieve your goal:

Either use the web interface to add your menu and view
Or create a custom module with python and xml
A quick overview of the seperate steps (for both ways mentioned above):

Create your new menu item at the specific position
Add a window action to the menu item to open your view
Create the view for your attachments
 

Let's start with the view. I will show you how to add a list view and you can add the kanban (and form) views, referring the offical view of the ir.attachment module.

If you choose to create a custom module, you will need a xml file with a designative name like project_attachment_view.xml. This file will contain the view, the action and the menu. The complete file content is surrounded by the tags <openerp> and <data> (xml tags are closed with the same tag with a slash in front </data> </openerp>). A view is a record of the module ir.ui.view and might look like that:

<record id="project_attachment_list_view" model="ir.ui.view">
    <field name="name">project.attachment.list.view</field>
    <field name="model">ir.attachment</field>
    <field name="arch" type="xml">
        <tree string="Project Attachments">
            <field name="name"/>
            <field name="datas_fname"/>
            <field name="description"/>
            <field name="res_name"/>
            <field name="file_size"/>
        </tree>
    </field>
</record>

The record name can be any name and the model is ir.attachments, since you want records of that model to be displayed. The architecture is of type xml and contains a tree view with some fields of the ir.attachment model. You can add all fields that are defined in a model (check ir_attachment.py for more fields).

If you decide to create your view via the web interface, create a new view under Settings -> Technical -> User Interface -> Views. (Make sure your user has Technical Settings checked under the users Access Rights).

Menu Items and Window Actions are also found under the Technical Settings menu.
Add all the required information according to the given code examples through the web interface.

 

Now for the new Window Action! In the same xml file add a new record for window actions like that:

<record id="open_project_attachment_view" model="ir.actions.act_window">
    <field name="name">All Files</field>
    <field name="res_model">ir.attachment</field>
    <field name="view_type">form</field>
    <field name="view_mode">kanban,tree,form</field>
    <field name="domain">[('res_model', '=', 'project.project')]</field>
    <field name="context">{}</field>
    <field name="view_id" ref="project_attachment_list_view"/>
    <field name="search_view_id" ref=""/>
</record>

The view_id should be the id that you have used for your previously coded view. view_type and view_mode are used to controll what kind of view are possible. The most tricky part is the domain. Since you want only documents displayed, that belong to projects, you have to filter all ir.attachment records. The field res_model contains the name of the related model. For the project model, the name is project.project.

 

Finally the menu item. Still in the same xml file add this:

<menuitem
    name="All Files"
    action="open_project_attachment_view"
    id="menu_open_project_attachment_view"
    sequence="20"
    parent="project.menu_project_management">
</menuitem>

The action is the id of the previously coded window action. The sequence gives the order of the menu items with the same parent menu. To have your menu item displayed after the Projects and Task menu, simply make the sequence big enough.

 

Last but not least, to make a module out of your xml file you need a new folder with a name like project_attachment. This folder should contain your xml file, a plain __init__.py file to tell python that the folder is a module, and a __openerp__.py file with further information. Your __openerp__.py should look like this:

{
    'name': 'Project Attachment Menu',
    'version': '1.0',
    'author': 'you@example.com',
    'description': """
Project Attachments
------------------------------

    """,
    'depends': ['project', 'ir.attachment'],
    'data': [
        'project_attachment_view.xml',
    ],
    'installable': True,
}

Support
Support
5000
| 2 1 2
Answered on 8/14/15, 2:39 PM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 8/14/15, 2:37 PM
Seen: 4180 times
Last updated: 8/14/15, 2:39 PM