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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

@api.depends not triggering function

Subscriure's

Get notified when there's activity on this post

This question has been flagged
ormapimethodapi.depends
6 Respostes
33933 Vistes
Avatar
Clément TheSecond

I created a stored (stored=True) computed field.

When  field related to this one are modified, I want to change the value of the field.

So I used @api.depense, as follow :

 
@api.multi @api.depends('lst_price','price','taxes_id','price_extra_ttc','price_extra') def _product_price_ttc(self):
    for record in self:
        record.price_ttc = round(record.lst_price * ( 1 + record.taxes_id.amount),2)

But when one the field of the 'depends' if modified, my function does not fire.

What is wrong with my code ?

1
Avatar
Descartar
Avatar
Clément TheSecond
Autor Best Answer

Finally the solution was : display the api.depends fields on the same page than price_ttc, so when those field are not on the same page that price_ttc, even if I update them, It's not working. 

I'm a bit desapointed : I thought that api.depends was working everywhere at every moment, but nope. All the fields must be in the same view than the modified one :(

4
Avatar
Descartar
Temur

I see... you've used store=True in your computed field?

Clément TheSecond
Autor

Yes sir ... but indeed, with a non-stored field, the displayed value is the good one.

Temur

Yes, I know about buggy behavior of compute field when store=True. In such a case it may display wrong value in certain conditions, but if you do not set store property then it works correctly(with default value: store=False). I agree with you, implementation of computed field leaves something to be desired if computed fields are stored fields as in your case. As by default store=Fasle for computed fields but you set it to True explicitly, it should be better to include field definition in your question... it's easy to skip extra information in question if provided, while it's harder to guess a missing part. One of the solutions for your case may be to remove store=True, if it does not affect anything else. You also found an interesting way to get it worked. cheers

Avatar
Bohdan Lisnenko
Best Answer

try @api.onchange

it triggers function when fields are changed in gui before writing to database

1
Avatar
Descartar
Clément TheSecond
Autor

Does api.onchange works when the computed field is not displayed ? Because, I can modify (for exemple) price_extra in a page, but price_ttc is not on this page. So, is it going to change price_ttc anyway ?

Bohdan Lisnenko

Yes, it should work. see http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html#api-onchange

Avatar
Temur
Best Answer

your function (that computes a field) will fire when you access the computed field (either when field is displayed in UI somewhere or included in UI as invisible or you access field from code using "my_browserecord.my_field", etc...) and NOT otherwise. There is nothing wrong with your code, just wrong expectation about when it should be fired.

0
Avatar
Descartar
Clément TheSecond
Autor

But when I refresh the page (within access to the computed field), the function does not trigger.

Temur

change one the field of the 'depends' and then refresh a page and function is not fired anyway? htat's your scenario?

Clément TheSecond
Autor

See answer above ... thank you anyway :)

Temur

it is possible that compute function is not fired if there is a valid cache. if you change any field listed in @api.depends, then cache will be invalidated, so after it if you access the field, function will be fired. Lets say we change 10 times one of the fields listed as dependency and after it we access the computed field once. In this scenario, if computed fields will be implemented as you expect, we'll have 11 call of compute function instead of 1 call. Why compute function should be fired unless it's absolutely necessary?

E.R. Spada

I am having the same issue: last_buy = fields.Date(compute='_get_lastbuys', string = 'Last Buy', store = True) last_pay = fields.Date(compute='_get_lastpays', string = 'Last Pay', store = True) @api.one @api.depends('credit') def _get_lastbuys(self): SaleModel = self.env['sale.order'] parser_model = report_sxw.rml_parse(self.env.cr, self.env.uid, self._name, context=self.env.context) orders = SaleModel.search([('partner_id', '=', self.id), ('state', 'in', ('progress', 'done', 'shipping_except', 'manual','invoice_except'))], order="date_order desc", limit=1) print "================== orders ====================", orders if orders: print "=================== DATE ORDER=================================", orders.date_order self.last_buy = orders.date_order return orders.date_order return @api.one @api.depends('credit') def _get_lastpays(self): SaleModel = self.env['account.voucher'] parser_model = report_sxw.rml_parse(self.env.cr, self.env.uid, self._name, context=self.env.context) vouchers = SaleModel.search([('partner_id', '=', self.id), ('state', '=', 'posted')], order="id desc", limit=1) if vouchers: self.last_pay = vouchers.date return vouchers.date return When I load the module or delete the fields, it will run and populate the DB, but never again, if I remove store=True, and remove api.depends, it will populate perfectly. But I need to search on this field, so added api.depends?

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
Related Posts Respostes Vistes Activitat
How to use the browse method to fetch all records, no a list of ids? Solved
orm method
Avatar
Avatar
1
d’ag. 15
31400
consistent keyError for api.depends
api api.depends
Avatar
Avatar
2
de jul. 15
11710
method name´s orm
orm method
Avatar
Avatar
2
de març 15
4907
[8.0] New API - Using Domains - ValueError: Invalid leaf Solved
api method 8.0
Avatar
Avatar
Avatar
5
de jul. 18
23253
ORM Create res.partner error Solved
automated actions orm api
Avatar
Avatar
3
de des. 19
6933
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