Skip to Content
Menu
This question has been flagged
2 Replies
2678 Views

how can I get the key of a many2one field in odoo 10

for example

color_id = fields.Many2one ('modelcolor', 'Cod.Colors')

cod_color=fields.char("cod.color")

where:

00-blue

01-red

@ api.onchange ('color_id)

      cod_color = self.color_id

I want the code of 00 or 01 to return, when the user selects a color.I need it to concatenate it with other data.

Avatar
Discard
Best Answer

Hi,

The question seems to be not clear. If you are looking to get the value of the cod_color in the Many2one field of the modelcolor , you can change the rec_name of the corresponding model to the cod_color.

class ModelColor(models.Model):
_inherit = "modelcolor"
_rec_name = 'cod_color'


Or if you need to get the cod color value in the change of the color field, try below code,

@api.onchange('color_id)
def change_color(self):
self.cod_color = self.color_id.cod_color



Thanks

Avatar
Discard
Author Best Answer

the code does not return any value, these are the models.

I wish that tcorr = tcod + A001

ex: tcorr = cod01 + A001

or tcorr = cod02 + A001, where cod01 (changes according to the field selection tdoc = many2one)

# -*- coding: utf-8 -*-
from odoo import _, api, fields, models

class einvoice_catalog_01(models.Model):
_name = "einvoice.catalog.01"
_description = 'Codigo de Tipo '

code = fields.Char(string='Codigo', size=4, index=True, required=True)
name = fields.Char(string='Descripcion', size=128, index=True, required=True)

@api.multi
@api.depends('code', 'name')
def name_get(self):
result = []
for table in self:
l_name = table.code and table.code + ' - ' or ''
l_name += table.name
result.append((table.id, l_name ))
return result


# -*- coding: utf-8 -*-

from odoo import models, fields, api

class inv13(models.Model):
_inherit='account.invoice'
tdoc=fields.Many2one('einvoice.catalog.01')
seri=fields.Char(string="seri")
corr=fields.Char(string="Correlativo")
tcorr=fields.Char(string="Union All")

@api.onchange(tdoc)
def change_tdoc(self):
        self.seri="A001"
self.tcorr=str(self.tdoc.code)+seri
Avatar
Discard