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

Filter Domain Field on Field

Suscribirse

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

Se marcó esta pregunta
openerp7domain_filter
2 Respuestas
11475 Vistas
Avatar
Knuckles

Hi guys i have some code like this

On the .py file

...

'date_received' : fields.date("Received Date")

'date_doc' : fields.date("Invoice Date")

...


On the .xml file i want to create search view on list view with filter domain date_received > date_doc, how can i achieve this?

Code below generate error 'undefined'

...

<filter domain="[('date_received','>', date_doc)]" help="Received Invoice"/>

...


Thanks

0
Avatar
Descartar
Avatar
Jignesh Jarsaniya
Mejor respuesta

Hello nuckles, 

I do have another solution to solve your problem. Let's create another boolean field to compare date range and use it on filter instead of using both date fields. You can follow the below things in the v7 coding pattern. 

According to v7 pattern

'is_received_date': fields.function(is_received_date, fnct_search=_func_search_is_received_date, method=True, type='boolean', string='Is Received Late')
def _func_search_is_received_date(self, cr, uid, obj, name, args, context):
match_ids = []
query = 'SELECT id FROM account_invoice ' \
'WHERE date_received > date_doc'
cr.execute(query)
for row in cr.fetchall():
match_ids.append(row[0])
if match_ids:
return [('id', 'in', match_ids)]
else:
return [('id', '=', 0)]


def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.date_received > line.date_doc
return res



According to Odoo v11 and v12 pattern

​compare_date = fields.Boolean(compute="_compute_compare_date", store=True)

@api.depends('date_received', 'date_doc')
def _compute_compare_date(self):
    for record in self:
        if record.date_received and record.date_doc and record.date_received > record.date_doc:
            record.compare_date = True
        else:
            record.compare_date = False

Add the following in your XML file.

<filter domain="[('compare_date','=', True)]" help="Received Invoice"/>

Hope this will help you. Please vote if you find a solution.

Thanks

1
Avatar
Descartar
Knuckles
Autor

Thanks for the answer, but if i take this approach then the existing record won't be filtered because it only affecting active form. I have to export all of the existing record and then update the compare_date my self so that the filter can work.

Jignesh Jarsaniya

Whenever we are adding any new compute field in Odoo model. It will automatically compute for existing records.

Knuckles
Autor

Yes, but the old record won't have the value

Jignesh Jarsaniya

I meant that Odoo is already doing for old records as well.

Knuckles
Autor

I'm using Openerp 7, so i can't use @api.depends. Any other way?

Jignesh Jarsaniya

Add a new field with v7 syntax and update the existing record's value by preparing the Postgres query. It might be super easy to update the value of existing record

Knuckles
Autor

I still can't get it to update every record. The active is updated fine. Here's my code

the field:

'is_received_date' : fields.function(is_received_date, method=True, type='boolean', string='Is Received Late', store=True)

the method:

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

if line.date_received > line.date_doc:

res[line.id] = bool(True)

else:

res[line.id] = bool(False)

return res

Knuckles
Autor

I shorten the method to:

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = line.date_received > line.date_doc

return res

Jignesh Jarsaniya

Sorry, I didn't have v7 environment to test it but at least you have the idea now might be you are doing something wrong in code. Thanks

Knuckles
Autor

i got it running, we need another function that search the whole record and place it in the field. Here's the code

the field:

'is_received_date' : fields.function(is_received_date, fnct_search=_func_search_is_received_date, method=True, type='boolean', string='Is Received Late')

the method:

def _func_search_is_received_date(self, cr, uid, obj, name, args, context):

match_ids = []

query = 'SELECT id FROM account_invoice ' \

'WHERE date_received > date_doc'

cr.execute(query)

for row in cr.fetchall():

match_ids.append(row[0])

print match_ids, 'lalalala match ids'

if match_ids:

return [('id', 'in', match_ids)]

else:

return [('id', '=', 0)]

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = line.date_received > line.date_doc

return res

Can you edit your answer to this? and i will mark your answer as a correct one.

Jignesh Jarsaniya

Thanks, I did it.

Avatar
Protagonist
Mejor respuesta

Hi,

Try to follow the below link

Filters using xml

0
Avatar
Descartar
Knuckles
Autor

Yes, i already know how to use normal filtering. But there is no example in the default module that compares 2 field from the same record.

¿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 access logged in user details in domain filter in openerp 7
python2.7 openerp7 domain_filter
Avatar
0
jun 18
3744
Domain Filter is not working on many2many field in OpenERP 7.0
openerp7 domain_filter odoo
Avatar
0
oct 15
4790
Dynamic Domain for states
domain_filter
Avatar
Avatar
1
may 24
3324
how can i assgin two different filters two same model but with different menu ? Resuelto
filter product openerp7 domain_filter
Avatar
Avatar
1
feb 24
5774
Odoo v16 domain, how to create a domain by user.company_id
domain_filter
Avatar
Avatar
1
nov 22
5927
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