Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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

Is it possible to get ids for filter from a Many2many relation that is on user.

Suscribirse

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

Se marcó esta pregunta
many2onemany2manydomain_filterodoo10
1 Responder
6864 Vistas
Avatar
Samo Arko

I've got a custom module that has a Many2one field on 'product.product'. I would like to extend 'res.users' with a Mayn2Many relation to 'product.product'. 

Is it in some way possible to filter the Many2one relation field 'product.product' in the custom module with the products that are selected in the Many2many field on the user that is logged in. 

And this cannot be done in python with onchange api that then gets the ids and returns it in domain. I don't have any field that I can use the on change except the one for products that I want to filter.  

1
Avatar
Descartar
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Mejor respuesta

You can use m2m field as a domain in m2o field.

Example:

<feld name="product_id" domain="[('id', 'in', product_ids)]"
<field name="product_ids"/>

Let me now if you mean by something else. This will show you only products in m2o field which are selected in m2m field.

You can set the domain dynamically using fields_view_get method.

from lxml import etree

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(class_name, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
for node in doc.xpath("//field[@name='product_id']"):
node.set('domain', "[('id', 'in', product_ids)]")
res['arch'] = etree.tostring(doc)
return res


5
Avatar
Descartar
Samo Arko
Autor

nope this is not what I need. In this example product_ids is on the same model. I need a way to get them from the active/logged in user. Like domain="[('id', 'in', [user.products_ids.ids])]" but it says that there is no user and no I can't have a user_id relation in the model, else I could do it with api.onchange.

Sudhir Arya (ERP Harbor Consulting Services)

Ah ok. Still you can do it by fields_view_get method. Just override this method and add a domain in the field. In the method you will be able to find the products of the logged in user.

product_ids = self.env.user.product_ids.ids

domain = [('id', 'in', product_ids)]

Samo Arko
Autor

hm... I never used this fields_view_get method, so I'll have to google a bit how to use it. So this forces the domain on the field? So this means that the filter will be active no mater the view? Because if yes I cannot use it, because I need it only in the form view in the list view I need all the records. Can define it only specific xml_id of view?

Sudhir Arya (ERP Harbor Consulting Services)

See my updated answers. You can do it for specific view as well. You can use "view_id" to add the domain on specific view:

self.env('module_name.form_view_xml_id').id == view_id

Samo Arko
Autor

mate thanks... needed a bit to figure out the method. Your example helped. Just needed to change/add

product_ids = self.env.user.products_ids.ids

node.set('domain', "[('id', 'in', {})]".format(tuple(product_ids)))

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

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

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Domain on Many2many without using a on_chnage
many2many domain_filter odoo10
Avatar
0
jul 22
2257
Default domain filter from method?
many2many domain_filter odoo10
Avatar
0
may 19
4689
[11.0] Hide records from many2many
many2many domain_filter
Avatar
0
ago 20
2896
Domain filtering many2one field dependent onchange from other field
many2one many2many onchange context domain_filter
Avatar
Avatar
1
abr 20
8185
how to get(show) many2many records by selecting the Many2one? in odoo10
many2one customers many2many onchange odoo10
Avatar
Avatar
2
ene 20
4869
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 de código abierto que cubren 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