0
votes

I have this class:

class caracteristica_fisica(osv.osv):
    _name = 'caracteristica.fisica'
    _columns = {
        'name': fields.char('Nombre',required=True),
 }

In product category, I have a many2one field making reference to caracteristica.fisica model:

class caracteristica_fisica(osv.osv):
    _inherit = 'product.category'
    _name = 'product.category'
    _columns = {
     'cf1':fields.many2one('caracteristica.fisica', 'Característica física 1')
    }

Once I select this many2one cf1 field, I need this value to generate a record in comun.denominador table:

class comun_denominador(osv.osv):
    _name='comun.denominador'
    _columns = {
          'categ_id' : fields.many2one('product.category','Categoría de Producto', select=True, ondelete='cascade'),
          'cf1_cm': fields.related('categ_id', 'cf1', string="Característica física 1", type='char', store=True, select=True),
     }

It generates the record in comun.denominador, but in this format:

caracteristica.fisica(4,)

and I need it to show the real name

How can I fix it?

1

1 Answers

0
votes

Try following:

class comun_denominador(osv.osv):
    _name='comun.denominador'
    _columns = {
          'categ_id' : fields.many2one('product.category','Categoría de Producto', select=True, ondelete='cascade'),
          'cf1_cm': fields.related('categ_id', 'cf1', string="Característica física 1", type='many2one', relation="caracteristica.fisica", store=True, select=True),
     }

The related field that you are trying to access is not of type "char", but a "many2one" field.

Note:

One more thing, if your purpose for having a related field just for the information purpose, don't make it "store=True" and make it readonly.