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

Function field Save in database

By
Prakash
on 10/28/13, 10:11 AM 4,109 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

0

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 12/5/13, 5:50 AM

'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

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

Prakash
on 12/5/13, 10:55 AM

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

Omal Bastin
on 12/6/13, 12:59 AM

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

0 follower(s)

Stats

Asked: 10/28/13, 10:11 AM
Seen: 4109 times
Last updated: 3/16/15, 8:10 AM