Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Cervecería
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y soporte técnico
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to get selected value from selection field

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
2 Respuestas
10031 Vistas
Avatar
ncmps

Hello!

I need to add two selection fields in products: one for manufacturer (For example: LG, Samsung) and another selection field for the model that would depend from the selected manufacturer. For example, if we selected LG, then in models field we'll see only models for LG, and if Samsung is selected, then only models for samsung we can select in models field.


I'm trying to get value of selection field, but always get ony None instead:


from odoo import models, fields, api


class ProductManufacturer(models.Model):
_inherit =
'product.template'

def get_manufactures(self):
manufactures = []
raw_data =
self.env['product.manufacturer.model'].search([])
for rec in raw_data:
manufactures.append((rec.manufacturer_id, rec.product_manufacturer))
return manufactures

def get_selected_value(self):
print('ALARM!')
print('ALARM', dict(self._fields['product_manufacturers'].selection(self)).get(self.type))
return ('one', 'ONE')

product_manufacturers = fields.Selection(get_manufactures,
string='Manufacturer', required=True)

product_models = fields.Selection(get_selected_value)


My function get_selected_value for testing, also alarms there for testing too ;)
Can anybody tell how can I get the value from selection field?

I'll be grateful for any help.
0
Avatar
Descartar
Avatar
ncmps
Autor Mejor respuesta
at the moment, I got it like this:

from odoo import models, fields, api


class ProductManufacturer(models.Model):
_inherit =
'product.template'

def get_manufactures(self):
manufactures = []
raw_data =
self.env['product.manufacturer.model'].search([])
for rec in raw_data:
manufactures.append((rec.product_manufact, rec.product_manufact))
return manufactures if manufactures else [('Nothing here :(', 'Nothing here :(')]


@api.depends('product_manufacturers')
@api.onchange('product_manufacturers')
def get_selection_name(self):
models_lst = [
'Nothing to show here :(']
if self.product_manufacturers:
raw_data =
self.env['product.manufacturer.model']\
.search([(
'product_manufact', '=', self.product_manufacturers)])
models_lst = raw_data.product_model.split(
',')
self.get_models_for_selection(some_lst=models_lst)


def get_models_for_selection(self, some_lst):
models_selection = [(model.strip(), model.strip())
for model in some_lst]
print(models_selection)
return models_selection

product_manufacturers = fields.Selection(get_manufactures,
string='Manufacturer', required=True)

product_models = fields.Selection(get_models_for_selection,
string='Product Models')

but it still doesn't work because of error: TypeError: get_models_for_selection() missing 1 required positional argument: 'some_lst'

I tried to make it with @staticmethod and there is no error, but then I have the empty field product_models.
0
Avatar
Descartar
Divyansh Tripathi

you are getting this some_list error because your method 'get_models_for_selection' takes an argument named some_lst but when you are giving it as a selection parameter you haven't passed any argument, I am talking about the following line

product_models = fields.Selection(get_models_for_selection, string='Product Models')

what you need to do is change some_lst param from being mandatory to option, something like this get_models_for_selection(self, some_lst=[]):

ncmps
Autor

Divyansh Tripathi, thank you for your answer. I solved my problem with a third-party module web_domain_field.

Avatar
bouthaina ayadi
Mejor respuesta

please can you tell me how u solved the problem with web_domain_field because i have the same problem

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones empresariales de código abierto que cubre todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now