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

Many2many field filtering based on selected contact id?

Suscribirse

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

Se marcó esta pregunta
domainmany2manyodoo10
1 Responder
11971 Vistas
Avatar
Samo Arko

I'm trying to get projects where the selected contact is the follower. I need it so I can select for which projects I should generate the report. For this I'm using a wizard with a Many2One field for selecting the contact and a Many2many field I want to use for checkboxes in the view.

Is it possible to set a dynamic domain that will filter the Many2many field?

contact_id = fields.Many2one('res.partner', domain="[('customers_tic_id', '!=', False)]")
project_ids = fields.Many2many(comodel_name='project.project',
                                   relation='project_document_wizard_rel',
                                   column1='document_wizard_id',
                                   column2='project_id',
                                   string='Contacts following projects',
                                   domain="[('project_id', 'in', self.followers_search_to_list())]")




def followers_search_to_list(self):
        tmp_list = list()
        followers = self.env['mail.followers'].sudo().search([('partner_id', '=', contact_id.id), ('res_model', '=', 'project.project')])

        for follower in followers:
            tmp_list.append(follower.res_id)

        return tmp_list

So what I'm doing wrong?

0
Avatar
Descartar
Avatar
Ibrahim Boudmir
Mejor respuesta

Hi, 

Your question is : can we set a dynamic domain that will filter M2M field based on Another M2O field? 

Answer : Yes you can. 

First, remove the domain from the M2M declaration. Then add a onchange function like this:

@api.onchange('contact_id')
 _onchange_contact_id(self):
    if self.contact_id:
        domain = [('project_id', 'in', self.followers_search_to_list())]
        return {'domain': {'project_ids': domain}}

Upvote if this helps. If not, you can write back for further analysis.
Regards.
5
Avatar
Descartar
Samo Arko
Autor

Thanks! I only needed to change 'project_id' to 'id'. And you forgot to say that I needed to add compute='_on_change_contact_id' to M2M field. Is there a way to not show any M2M records until the contact is selected? Now I get all existing projects until I select the contact.

Samo Arko
Autor

I can't click on any of the checkboxes!?

Ibrahim Boudmir

Hi,

1- I did not forget to mention that the field should have compute attribute because simply it should not.

2- Not show M2M record until contact is selected : in onchange_contact_id, i only added the condition where contact is set. In this case, you can add 'else' then apply another domain that suits your need.

3- you can't click on any of the checkboxes because you made the field compute... compute field is readonly. Since that is not what i suggested, remove compute attribute.

but to enlighten you more, even if a field is computed, you can still add records manually by adding the attribute "inverse".

Hope this helps you.

Samo Arko
Autor

yeah I figured that about compute field out, so I removed it and it saves. But the problem that I've got now is when the record is saved and when I open it again (go to a different view and back) there are again displayed all projects. But at least the ones that were selected remain selected.

Vysakh B Thottarath

@Tabla : I also have the same problem while using onchange for domain.You got any other solutions ?

Samo Arko
Autor

You need to specify the problem a bit more. But mostly the solution suggested worked for me. If you created a post with the problem explained and some code then post me the link in the comment.

Yeison X

Hi.

Can I do this with Automated Actions?

I have a many2one field (res.partner) and a many2many field (account.move)

When I select the partner, I want only to show the account move documents related with the partner selected.

I'm wondering if it's possible to achieve this with a automated actions and a python code.

Thanks

ahmadsalih7

Thank you, it works !!

¿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
Many2many domain works when click search more but wrong values in dropdown
domain many2many
Avatar
0
nov 22
80
[SOLVED] Create rule using many2many - how to? Resuelto
domain many2many
Avatar
1
jun 22
8125
Many2many domain not working Resuelto
domain many2many
Avatar
1
jul 21
3527
Many2many domain not working Resuelto
domain many2many
Avatar
Avatar
1
jul 21
5036
How to Update Many2Many Relation Table Records in Odoo 10 Resuelto
many2many odoo10
Avatar
Avatar
2
may 17
11863
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