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

Return value in field function openerp v7

By
lam a bao
on 11/28/13, 10:35 PM 2,919 views

Hi erveryone: I have function :

  def getcodesystemdoor(self, cr, uid, ids,fields, arg, context=None):

          x={}
         getids= self.read(cr,uid,ids,['demomany2one'])[0]['demomany2one']
         get_oj=self.pool.get('product.category')
         search_oj=get_oj.search(cr, uid, [('id', '=',getids[0])])
       data_oj=get_oj.read(cr, uid, search_oj, ['id','parent_id'], context)
       for item in data_oj:
           x[item.id]=item['parent_id']
       return x

and columns:

"codesystemdoor":fields.function(getcodesystemdoor,method = True, String='Sum cost',type="integer")

when I excute , error 'list' object has no attribute 'get'

can you help me ?

I think your search_oj is a list. Try using it like: search_oj[0] or add: limit=1 to search methods arguments when initializing it.

Jaakko Komulainen
on 11/29/13, 2:41 AM
0
Julio Serna
On 11/29/13, 8:46 PM

If "demomany2one" field is of type "many2one" you can try this:

def getcodesystemdoor(self, cr, uid, ids,fields, arg, context=None):
        x={}
        get_oj=self.pool.get('product.category')
        for item in self.browse(cr, uid, ids, context=context):
            search_oj=get_oj.search(cr, uid, [('id', '=', item.demomany2one.id)])
            data_oj=get_oj.browse(cr, uid, search_oj, context=context)[0]
            x[item.id]=data_oj.parent_id.id
        return x

best regards

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: 11/28/13, 10:35 PM
Seen: 2919 times
Last updated: 3/16/15, 8:10 AM