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

Functional field error

By
Diego Calzadilla
on 4/8/15, 2:55 PM 1,676 views

I have defined this functional field so that I can get values from one2many field and display them in tree view:

    def get_product_brands(self, cr, uid, ids, fields, arg, context):

        context = context or {}

        res={}

        for record in self.browse(cr, uid, ids, context=None):

            brands = ''

            for val in record.application_data_product_template_ids

                if val.brand.name:

                    brands += "%s " % (val.brand, )

                print brands

            res[record.id] = brands and brands[:-1] or ""

        return res


my field defintion:

'brands' : fields.function(get_product_brands, method=True, string="Product brands", type='char')


But I'm getting this error:


File "/home/odoo/addons/bal_dev/balerce_dev.py", line 209, in get_product_brands_2

for record in self.browse(cr, uid, ids, context=None).application_data_product_template_ids:

File "/home/odoo/openerp/fields.py", line 755, in __get__

record.ensure_one()

File "/home/odoo/openerp/models.py", line 5219, in ensure_one

raise except_orm("ValueError", "Expected singleton: %s" % self)

except_orm: ('ValueError', 'Expected singleton: product.template(8, 4, 5, 9, 2, 3, 7)')

application_data_product_template_ids is your field? in this model?

zbik
on 4/8/15, 4:57 PM

application_data_product_template_ids, is a new one2many field in product.template model. I use this field to store brand values. What this function needs to do is to fetch all brand values stored in this new one2many field

MEXYTUL, Diego Calzadilla
on 4/8/15, 5:22 PM
1

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 4/8/15, 5:33 PM

Hi,

You can't use '.' operator here,

self.browse(cr, uid, ids, context=None).application_data_product_template_ids: 

because self.browse(cr, uid, ids, context=None)  contains more than one record.

you can iterate that or make sure it will receive single record

That's why you are getting -> 'ValueError', 'Expected singleton

Hope this helps....


2

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/8/15, 6:57 PM

I modify your code in your post, should work, bye

if val.brand.name: brands += "%s " % (val.brand.name, ) words = brands.split() new_brands = ' '.join(sorted(set(words), key=words.index)) Added this, so that I can eliminate reapeted values....thanks!!

MEXYTUL, Diego Calzadilla
on 4/8/15, 9:48 PM

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

1 follower(s)

Stats

Asked: 4/8/15, 2:55 PM
Seen: 1676 times
Last updated: 4/8/15, 9:49 PM