Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3927 Vistas

hello this is my code:

from odoo import models, fields, api

class gestion_marcas(models.Model):

 _name = 'gestion_vehiculos.gestion_marcas'
marcas = fields.Char(string='Marca') 

marca_id = fields.Integer(string='Id') 


class gestion_vehiculos(models.Model):

 _name = 'gestion_vehiculos.gestion_vehiculos' 

_inherit = 'gestion_vehiculos.gestion_marcas'
marca = fields.Many2one('gestion_vehiculos.gestion_marcas',string='Marca') 

modelo = fields.Char(string='Modelo') 

dateto = fields.Date(string='Año') 

color = fields.Char(string='Color')

 placa = fields.Char(string='Placa') 

vin = fields.Char(string='Vin')

Avatar
Descartar

solution 1: you must use name field in your model
solution 2: if you havn't name field than use _rec_name = 'some_field', in your model

Mejor respuesta

Hi,

As there is no name field in the newly added model, in order to resolve this, you have to add _rec_name for the model or you have to define the name_get function for the model.

By default, in the many2one field, the name field is shown from the corresponding model, when it is not there in the model and no rec_name and no name_get function, it will show as account.invoice(1) etc.


So to solve problem, you have three options.

1. Define a field with technical name as name

2. Define rec_name for the model. For that see: https://www.youtube.com/watch?v=d_cyPsVc7vg

3. Define name_get function. See: https://www.youtube.com/watch?v=aT_tsfW5HaQ


Thanks

Avatar
Descartar
Autor Mejor respuesta

Thank you very much it worked very well for me. but now I have another problem since I want to relate the models class with the brands class and when doing the inheritance it adds all the fields of the class.

from odoo import models, fields, api

class gestion_marcas(models.Model): 

_name = 'gestion_vehiculos.gestion_marcas' 

_rec_name='marcas'
marcas = fields.Char(string='Marca') 

marca_id = fields.Integer(string='Id de Marca')

class gestion_modelo(models.Model):

 _name = 'gestion_vehiculos.gestion_modelo' 

_inherit = 'gestion_vehiculos.gestion_marcas' ## this is the inheritance

 _rec_name='modelos' 

id_modelo =fields.Integer(string="ID de Modelo") 

modelos = fields.Char(string='modelos') 

marcas_id = fields.Many2one('Gestion_vehiculos.gestion_marcas',string='Marca')##this is the field that will relate the two tables

 class gestion_vehiculos(models.Model):

 _name = 'gestion_vehiculos.gestion_vehiculos' 

_inherit = {'gestion_vehiculos.gestion_marcas' ,'gestion_vehiculos.gestion_modelo'}

 _rec_name='placa' 

marca = fields.Many2one('gestion_vehiculos.gestion_marcas',string='Marca') 

modelo = fields.Many2one('gestion_vehiculos.gestion_modelo',string='Modelo')

 dateto = fields.Integer(string='Año')

 color = fields.Char(string='Color')

 placa = fields.Char(string='Placa') vin = fields.Char(string='Vin')

Avatar
Descartar