跳至內容
選單
此問題已被標幟
3 回覆
8096 瀏覽次數

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)

頭像
捨棄
作者 最佳答案

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.
頭像
捨棄
最佳答案

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.



 




頭像
捨棄
作者

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

相關帖文 回覆 瀏覽次數 活動
3
6月 23
12399
1
6月 16
5261
0
12月 23
6648
2
4月 19
10438
0
8月 24
4423