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

Filter and group_by for many2many fields. How to do that?

Suscribirse

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

Se marcó esta pregunta
filtermany2manygroup_by
1 Responder
21855 Vistas
Avatar
Paulo Matos

Hello everyone,

I am trying to create a group for my search view which includes a many2many field.
When I try to load the "group by" option I have created for this many2many field, I get the error:

assert gb_field.store and gb_field.column_type, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True

My many2many field is declared as:
mechanic_ids = fields.Many2many('res.users', relation='timesheet_rel_users', column1='id',column2='name') 

On XML for the search view I have:

The above error is raised when I try to load this specific "group by" option.

Is there any way I can create a "group by" option which includes a many2many field?

Thank you in advance

Best regards

Paulo

0
Avatar
Descartar
Avatar
faOtools
Mejor respuesta

It is not possible to group by many2many field.

In that case the line might be shown on the Odoo interface more than one time, what is not acceptable.

As alternative you can create a many2one field which would compute the 'main' record from many2many. For example, you can group partner by tags, but you can group by some computed 'main tag'.

Besides, search by many2many field would work. An example from res.partner: 

<field name="category_id" string="Tag" filter_domain="[('category_id','ilike', self)]"/>

Also you may generate some custom report for your model, which would join tables in the way you like (SQL statement).

UPDATE

@api.multi
@api.depends('mechanic_ids')
def _compute_mynewfield_id(self):
for record in self:
record.mynewfield_id = record.mechanic_ids and record.mechanic_ids[0] or False


mynewfield_id = fields.Many2one('mechanic_ids', compute=_compute_mynewfield_id, store=True) # it is possible to search only among stored fields

4
Avatar
Descartar
Paulo Matos
Autor

Hi @Odoo Tools,

Thank you very much once again for your help on my path on learning Odoo development.

I have tried to create a "computed" field for this purpose I was unable to do it.

Can you please help me with a sample code?

My many2many field is declared as:

myfield_ids = fields.Many2many('res.users', relation='timesheet_rel_users', column1='id',column2='name')

I have tried to create a many2one computed field declared as:

mynewfield_id = fields.Many2one('mechanic_ids', compute='_get_values, store=False)

My incomplete function:

@api.one

@api.depends('mechanic_ids')

def _get_values(self):

value = self.mechanic_ids

for record in value:

I am stuck from this point forward.

From here, If I print the "value", I can get the desired value for every and each record, but do not know how to complete the function and pass it to XML view filter.

Thank you once again

Best regards

Paulo

faOtools

see the update

Paulo Matos
Autor

Dear @Odoo Tools,

Thank you very very much once again.

+1000 for you

Best regards

Paulo

¿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
Remove a value from many2many related field. How to do that? Resuelto
filter many2many
Avatar
Avatar
Avatar
2
jul 19
12013
Create e list from records on many2many relational field Resuelto
filter many2many
Avatar
Avatar
1
jun 19
7680
How to add domain filter & default 'group by 'to the existing field in inherit model
filter group_by odoo16features
Avatar
0
feb 23
3345
Expand "group by" filter by default
filter group_by filtering
Avatar
Avatar
1
ago 21
12283
How to Use Domain Filter with Many2Many field
filter domain many2many
Avatar
Avatar
1
ago 24
8595
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