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

fill many2many field from other many2many field

By
Diego Calzadilla
on 3/24/15, 11:33 AM 875 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?

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

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

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: 3/24/15, 11:33 AM
Seen: 875 times
Last updated: 3/24/15, 12:10 PM