This question has been flagged
2 Replies
14245 Views

Hey everybody

Since today I'm experimenting with Odoo 8 its project management module. 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.
What I would like to get is this:

And then when you click on this menu item you would get a view which shows ALL attached files for ALL projects. For example:


Could anybody tell me how to program this or build it? I'd like to learn more about customizing modules but I don't know how or where to start..
EDIT: I found some documentation at https://www.odoo.com/documentation/8.0/howtos/backend.html but it doesn't help me much further..

Thank you
Yenthe

Avatar
Discard
Best Answer

This is not the easiest task to start customizing Odoo (OpenERP).

Anyways, there are two ways to achieve your goal:

  1. Either use the web interface to add your menu and view
  2. 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. From your screenshots I can see, that you want a kanban view for the attachments. I'm not very experienced with kanban views, so 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,
}

 

you should be able to install your new module if you place your new project_attachment folder under an valid addons folder. All addon folders are listed in the openerp-server.conf file of your OpenERP installation after the keyword addons_path as comma seperated list.

 

Hope I could help.

 

Avatar
Discard
Author

Thank you very much for this big answer René! Could you tell me why I'm not seeing any attachments though? I can see the new menu items, see that I can access the kanban view etc but I can't see any files.. Is there a reason for that? And would you mind asking me some more questions tommorow? This is quite a lot and I'd love to understand every part so I can do this for myself from now on! This put me a step forward!

Author

@René I do understand this for the most part but why doesn't it show me any files? I've tried without the domain etc but I can't get any files to show up. What am I missing / is missing in the code? Don't seem to get this working..

Are there attachments stored in your current database? There is the option, that your user does not have access rights for the ir.attachment module.

Author

Yes I have multiple attachments in my database as I've attached a few files to my projects. My user is the main administrator, with technical features and developer mode on so he should be able to see everything? I'm not sure why nothing is showing up.

Strange. Try to alter the view_mode to "tree,form" in the window action, or remove the whole lines for "view_id" and "search_view_id".

Author

Removing the view_id and search_view_id doesn't fix anything. What exactly do you mean by altering the view mode in the window action? Do you mean in the code to edit the record and then under tree,form in place of tree,form,kanban? Because this doesn't work either..

Best Answer

You can start here:

https://doc.odoo.com/

Avatar
Discard
Author

Sadly there is no information about customizing menu's or about how to write your own modules..

You must search a bit, but the info is there:

https://doc.odoo.com/trunk/server/

Example of module creation
https://doc.odoo.com/trunk/server/03_module_dev_05/

Menus information
https://doc.odoo.com/trunk/server/03_module_dev_04/