Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Computed field is not triggered

Subscriure's

Get notified when there's activity on this post

This question has been flagged
2 Respostes
22607 Vistes
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
Best Answer

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
Best Answer

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.)

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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