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
    • e-learning
    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
    • Conocimientos
    • 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 pub
    • 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
    • Cervecería
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y soporte técnico
    • 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
    Explorar todos los sectores
  • 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
    • Servicios para 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

Computed field is not triggered

Suscribirse

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

Se marcó esta pregunta
2 Respuestas
22640 Vistas
Avatar
José

Hello, I have Odoo 8.

I have a computed field in a model

    pricelist_version = fields.Many2many('product.pricelist.version', 'pagos_vouchers', 'id_voucher', 'id_pago')
    fue_usado = fields.Boolean(compute='_cuenta_pagos', store=True)

    @api.one
    @api.depends('pricelist_version')
    def _cuenta_pagos(self):
        if(len(self.pricelist_version) > 0):
            self.fue_usado = True
        else:
            self.fue_usado = False

I modify the value of 'pricelist_version' (I can check this because I add a field that shows the pricelist_version asociated with the model in a view) but the _cuenta_pagos method is not triggered and I don't found my mistake. Where is it?

Edit: If I modify the pricelist_version values in the view of the model, the method is triggered. But if I modify this from the pricelist_version view, the method is not triggered.

Edit @Bole:

    pricelist_version = fields.Many2many('product.pricelist.version', 'pagos_vouchers', 'id_voucher', 'id_pago')
    fue_usado = fields.Boolean(compute='_cuenta_pagos', store='_check_to_recompute')

    def _check_to_recompute(self, cr, uid, ids, context=None):
        return [ids]

    @api.one
    @api.depends('pricelist_version')
    def _cuenta_pagos(self):
        if(len(self.pricelist_version) > 0):
            self.fue_usado = True
        else:
            self.fue_usado = False

0
Avatar
Descartar
Avatar
Bole
Mejor respuesta

Parameter store=True defines such behaivour... 
to be precise... it computes the stored value once, store it in db field and never recompute again.. 

In order to test this behaivour, first remove store=True param... and try changing values ( it should recompute on each view reload...)
refer to documentation for more info on subject

 

hope it helps

edit1:

Parameter store = True, can accept a list of ids to recompute.. , so you should make store=_check_to_recompute

and def _check_to_recompute(self,...):

   return [ids]

returning any list of ids to store parameter of computed field will trigger recompute on those fields, and making store=_some_method is basicly store != False , so the data will be store.. .
look at documentation for v7 .. might be more explanational... also look for new api documentation on link above

 

EDIT 2.

Look at account_invoice example.. 
    @api.one
    @api.depends('invoice_line.price_subtotal', 'tax_line.amount')
    def _compute_amount(self):
        self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line)
        self.amount_tax = sum(line.amount for line in self.tax_line)
        self.amount_total = self.amount_untaxed + self.amount_tax

according to this, _compute amount is triggered whenever invoice_line.price_subtotal, or tax_line.ammount is changed...
maybe go that way.. try to debug/test on account_invoice model for beter comprihesion of this subject

1
Avatar
Descartar
José
Autor

You are right, if I delete store=True the computed field works correctly. But if I remove store=True I can't use the computed field in a domain. How can I do this? Thanks!

José
Autor

@Bole, show my edit

Bole

Unfortunatly, i'm still working mainly with v7 api, will ake some private tests and reply as soon as i get some result... i know how to do it old-style api... so that might be a good starting point... ( maybe try fileds.function on v7 api ? ) oll theory here is based on it...

Avatar
Ivan
Mejor respuesta

Check the addons/account/account_invoice.py for samples.  You need to specify change in what field in pricelist_version that will trigger the recompute of fue_usado. E.g.  @api.depends('pricelist_version.active').  If you need it to be triggered in every save, try write_uid field (you might need to define write_uid in product.pricelist.version).

1
Avatar
Descartar
José
Autor

It works when I add a pricelist_version, so pricelist_version length is more than 0. This turns 'fue_usado' to true. But when I delete all the pricelist_version objects related to the object, 'fue_usado' still is true. Why?

Ivan

Have you tried combining both? @api.depends('pricelist_version', 'pricelist_version.active'). Just list down all potential triggers. The part when you remove the last object is because there is no triggering records anymore.

José
Autor

And how can I do to trigger the method when there are not records?

Ivan

By using a change of another field. The inclusion of 'pricelist_version' should do it because it will trigger the write if there is any change in pricelist_version (i.e. addition, removal, etc.)

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

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

Inscribirse
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 empresariales de código abierto que cubre 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