Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Implementing a tag system for attachments

By
Marco Liceti
on 12/6/15, 6:03 AM 423 views

I've been asked to develop a tag system for attachments.

While for attachments I've used the Document Management System module, I didn't find anything useful for tag management.

Thus, I've developed my own, custom module in which attachments (ir.attachment model) have been extended with a Many2many relation with a tag model, that in turn represents... a tag, and has a tag field representing the actual tag's textual content.

Then I've been struggling with search by tag... 

The problem here is that the searched term has to be compared with a related object's fields (i.e. the tags), not with a field of the attachment itself.

So I came up with a workaround. I've extended the attachment model with:

  • a computed char field called tags with an associated custom search method _search_tags

  • a boolean field called found_by_tag

_search_tags is invoked each time a search is performed and its job is to set the flag found_by_tag to the proper value, based on the searched term.

Thus, the expression for the search view becomes [('found_by_tag', '=', True)].

Note: For the actual code, check this stack overflow question: http://stackoverflow.com/questions/34086330/odoo-implementing-a-tag-system-for-attachments

While the workaround actually works, I'm wondering if that's too much. Is there a simpler way to implement a search by tag? Or, alternatively, is there a module that may be used for this purpose?

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!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/6/15, 6:03 AM
Seen: 423 times
Last updated: 12/6/15, 6:03 AM