This question has been flagged
1 Reply
5581 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']):

            attributes_product_template.append((0,0,{'value_ids':attribute_id['value_comun_denominador_ids'][0],'attribute_id':attribute_id['attribute_comun_denominador_id'][0]}))

            value.update(attribute_line_ids=attributes_product_template)

        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?

Avatar
Discard
Author Best Answer

Problem solved, I changed

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


value_ids':attribute_id['value_comun_denominador_ids']


I hope this is useful for someone else

Avatar
Discard