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
    • eLearning
    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
    • Información
    • 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 taberna
    • 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
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • 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
    Browse all Industries
  • 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
    • Services for 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

[Odoo 12] How to perform a search on a One2many field through a wizard?

Suscribirse

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

Se marcó esta pregunta
wizardone2manysearch12.0
2 Respuestas
15985 Vistas
Avatar
Willem Datema

Hello all,

I am trying to perform a filter/search through a wizard for a One2manyfield. The One2manyfield connects to the model stock.picking. I created a TransientModel in which a user can pick a Sale Order and the wizard should return a form with a filtered one2many field. The form will then only show the pickings which have the Sale Order that the user selected as Origin. The TransientModel looks like this:

class SearchPacking(models.TransientModel):
    _name = 'search.packing'
_description = 'Search a packing'

sale_order_id = fields.Many2one('sale.order',string="Sale Order")

def search_filtered_packing(self):
return {
'type':'ir.actions.act_window',
'view_type':'form',
'view_mode':'form',
'src_model':'search.packing',
'res_model':'pickpack.packview',
'target':'new',
'res_id':self.env.context.get('active_id'),
'domain':[('origin','=',self.sale_order_id)]
}


The model pickpack.packview is a model that shows all the pickings with picking type "Pack" in a batch. It has a one2many field that looks like this:

class PackView(models.Model):
    // OTHER DEFINITIONS ​   ​    ​   ​     ​   ​    ​   ​
    pickings = fields.One2many('stock.picking','packviews',string='Operations to pack',readonly=False,store=True, compute='_compute_operations_to_pack')
@api.one
@api.depends('batch_id')
def _compute_operations_to_pack(self):
self.ensure_one()
res = self.env['stock.picking']
for picking in res.search([('batch_id','=',self.batch_id.id),('picking_type_id.name','=','Pack')]):
res += picking
self.pickings = res

What happens now if I click the button in the wizard that calls search_filtered_packing (after selecting a Sales Order) is that I just get the same model back, without any filters. 
The One2Many field is searchable on Sales Order in the tree view. Can anyone see what is going wrong here?


Thanks in advance.

0
Avatar
Descartar
Avatar
Ryan Tran
Mejor respuesta

Hi,

There are some problems in your solution:

  • If you really mean to compute the One2many field, you should not define it with the inverse_name. By doing this, there are no real connection between these 2 models, and you cannot store this o2m field. If the relation already exist between 2 model with the m2o relation defined in the corresponding model, then you can only apply domain to decide what to be shown.

  • You cannot domain a form view, but you can domain a field shown as tree in the form view, if you return correct value to domain that field in particular.

Then the solution now is depends on what you want to achieve:

  • You can add a sale_order_origin to stock.picking form view to apply domain dynamically to the related one2many field, with an onchange function.

  • If you want to use the wizard, then from that wizard, you select the reference Sale Order, then assign the result recordset to an m2m field on the wizard, and then finally write those m2m ids to the o2m field in stock.picking.

I think you would want to domain what to be picked base on the Sale Order (delivery operation) rather than automatically creating o2m record from the wizard. Then returning domain for a selected field using onchange function is your best friend. Try :

return {'domain':{'picking_ids': [('origin', '=', self.sale_order_id.name)]}}
1
Avatar
Descartar
Avatar
faOtools
Mejor respuesta

You return a form view and, moreover, you return res_id in your method. So, you say to Odoo - 'show me a form of this object in a new window'. The param domain is applied to tree, kanban, calendar views: so to any where there are a few items.

A few other comments:

  • How might origin (char) be equal to sale_order_id (recordset)?

  • What for do you need 'src_model'?

Thus, you should re-develop your action to return, for example a list. Something like:

@api.multi
def search_filtered_packing(self):
self.ensure_one()
return {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'pickpack.packview',
'type': 'ir.actions.act_window',
'domain':[('origin', '=', self.sale_order_id.name)],
}
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
Publicaciones relacionadas Respuestas Vistas Actividad
How to open wizard from "Add a line" link of One2many field?
wizard one2many
Avatar
Avatar
1
jun 24
443
Smart search of phone numbers. Resuelto
search 12.0
Avatar
Avatar
2
dic 20
5647
Read values from one2many relation
one2many search
Avatar
Avatar
1
nov 18
3507
One2many through wizard, (without errors, but no add to the record)
wizard one2many
Avatar
Avatar
1
feb 16
5727
One2many field on wizard opens by itself
wizard one2many print
Avatar
Avatar
1
sept 23
2863
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 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 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