This question has been flagged
1 Reply
9612 Views

In Openerp 7 Functional field added with store in Database

I used the below code:-

    def _concat_attached_file(self, cr, uid, ids, name, arg, context=None):
        res = {}
        attachment_obj = self.pool.get('ir.attachment')
        for id in ids:
            procedure_attachment = attachment_obj.search(cr, uid, [('res_model', '=', 'model_name'), ('res_id', '=', id)], context=context)
            filelist = []
            for val in attachment_obj.browse(cr, uid, procedure_attachment):
                filelist.append(val.name)
            filevalue = ', '.join(filelist) 
            if not filevalue:
                filevalue = None            
            res[id] = filelist
        return res

  'attached_file'   : fields.function(_concat_attached_file, method=True, store=True,  string='Attached File Name', type='char'),

But the above functional fields generate output only with Store=False. Suppose used Store=True output not generated. I want to store the db also how to fix ?Thanks

Avatar
Discard
Best Answer

'store'=True will store the value of the field in database. Once stored then the functional fields function will not be executed again. if 'store'=False, then every time(any change in the record) the functional field will be executed

But if the value of 'store' is a dictionary then (key of the dictionary will be a model name and value will a tuple with list of ids, list of field name and 10-i dont know ) any change/update in the model specified as the key of the dictionary and change/ update is in the ids specified in the tuple and change or update is in the field names specified in the list then the function of the functional field will be loaded and new data will be saved in database

Avatar
Discard
Author

Hi Omal Bastin, Thanks for reply I have another doubt In openerp 7 i want to shows attached file shows in list view and store in DB. After attached the file [using default options Wizard Attachments Add] method the function not called. So write method overridden and called the function. But how to shows the attachment document after attached to call function automatically [without using write method override] Thanks

Hi, goto res.company model and check how the image is saved and showed in the ERP. There you can find a better example for what your are looking for