This question has been flagged
3 Replies
6890 Views

I am implementing the Knowledge Management module in odoo v8 and I have come across a major short coming.The directory field in the attachments is not automatically set by the system even if I configure the "Folders per resource" part in Knowledge.

For example, I have a Clients folder whose parent folder is documents. This folder is set as "Folders per resource" for the partner model. Now, if I attach an attachment on a customer, it is not being placed in the clients folder by default.

Does anyone know how to make attachments in odoo to go to a specific directory by default so I don't have to manually set the directory field in the attachment form. I feel this is a vital feature in as documents organisation is concerned. 

(Please upvote the question so that I can be able to comment)

Avatar
Discard
Author Best Answer

I found some great explanation here https://www.odoo.com/forum/help-1/question/where-are-document-attachments-stored-529 (Antony Lesuisse's answer) on how to set odoo to save the attachments in the file system.

I then used the following piece of code to set a default for 'parent_id' field in the attachment. (ir.attachment class)

from openerp.osv import osv, fields
from openerp.tools.translate import _
class ir_attachment(osv.osv):
    #extend document
    _inherit = "ir.attachment"
    def create(self, cr, uid, vals, context=None):
        if context is None:
            context = {}
        if not vals.get('res_model', False) and context.get('default_res_model', False):
            vals.get['res_model'] = context.get('default_res_model', False)        
        if not vals.get('parent_id', False):
            parent_id = self.pool.get('document.directory').search(cr, uid, [('ressource_type_id','=',vals.get('res_model'))])
            if parent_id and parent_id[0]:
               vals['parent_id'] = parent_id[0]
            else:
                vals['parent_id'] = self.pool.get('document.directory')._get_root_directory(cr,uid, context)
        
        return super(ir_attachment, self).create(cr, uid, vals, context)
ir_attachment()
class document_directory(osv.osv):
    _inherit = 'document.directory'
    _sql_constraints = [
        ('dir_uniq', 'unique (ressource_id,ressource_parent_type_id)',
         'The Directory name must be unique per Resource Type and Resource !'),
    ]
This atleast did what I needed.
Avatar
Discard
Best Answer

Hello Cyrus,

The functionality "Folders by resource" only works in relation to module "document_ftp". That is, when you access to your repository using FTP, the application dynamically constructs one folder per resource (e.g. one folder for each sales order), based on the flag that you set to the 'Customers' folder in Odoo. These are not physical but 'virtual' folders.

What you ask for is interesting, but would require a specific development, so that each object in Odoo would create it's own physical folder per resource.


Regards,

Jordi.



 




Avatar
Discard
Author

Unfortunately, document_ftp has not been ported to odoo v8. Please see how I achieved what I wanted in my answer below