Odoo Help


fill many2many field from other many2many field

Diego Calzadilla
on 3/24/15, 11:33 AM 1,695 views

Hi, in odoo core code exists this field('product.attribute.line' model):

    'value_ids': fields.many2many('product.attribute.value', id1='line_id', id2='val_id', string='Product Attribute Value')

I created custom module, in my new model('attribute.comun.denominador.line' model) I have this field:

    'value_comun_denominador_ids': fields.many2many('product.attribute.value', id1='line_id', id2='val_id', string='Product Attribute Value')

All I need to do is to update values of field 'value_ids' using values of 'value_comun_denominador_ids' by means of onchange function, so I created this function:

    def on_change_cm_id(self,cr, uid, ids,cm_id,context=None):

        context=context or {}

        attributes_product_template = []

        value = {}

        if ids:

            old_note_ids = self.pool.get('product.attribute.line').search(cr, uid,[('product_tmpl_id','in',ids)])

            self.pool.get('product.attribute.line').unlink(cr, uid, old_note_ids)

        attribute_cm_ids = []

        attribute_cm_ids = self.pool.get('attribute.comun.denominador.line').search(cr, uid, [('comun_denominador_id', '=', cm_id)])

        for attribute_id in self.pool.get('attribute.comun.denominador.line').read(cr, uid, attribute_cm_ids,  ['attribute_comun_denominador_id', 'value_comun_denominador_ids']):



        return {'value':value}

This function works fine with many2one fields ('attribute_comun_denominador_id') but in the case of many2many fields(value_comun_denominador_ids), I get this error:

    File "/home/odoo/openerp/fields.py", line 1568, in convert_to_cache raise ValueError("Wrong value for %s: %s" % (self, value))

ValueError: Wrong value for product.attribute.line.value_ids: 1

Please, how can I do correct migration between many2many fields, some example?

Diego Calzadilla
On 3/24/15, 12:10 PM

Problem solved, I changed

'value_ids':attribute_id['value_comun_denominador_ids'][0]    and wrote:


I hope this is useful for someone else

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/24/15, 11:33 AM
Seen: 1695 times
Last updated: 9/11/17, 3:49 AM