Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

"RuntimeError: maximum recursion depth exceeded in cmp" problem

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
one2manyodoo10
4 Risposte
12070 Visualizzazioni
Avatar
Samo Arko

I've got a weird problem when I call child refresh() method in parent model it works, but if I call it in the child model I get the runtime error.


# Working method in the parent model
@api.multi
def write(self, vals):
record = super(ParentModel, self).write(vals)
for child in self.child_ids:
child.refresh()

# method in child model that throws the error
@api.multi
def write(self, vals):
record = super(ChildModel, self).write(vals)
self.refresh()


The refresh method is calling all the computed methods of the child model and methods that just set data. And I need to call it in the child model when I'm setting data on the child model view and not on the parent model view.

So any ideas how to fix this or why it's happening?

Oh, I've found that this can happen if you have any depends methods, and I call them, but it fails on the every method! I tried commenting them out.

@api.multi
def refresh(self):
for rec in self:
rec._method1()
rec._computed_method1()


0
Avatar
Abbandona
Avatar
Jigar Vaghela (jva)
Risposta migliore

don't do refresh under write method. in your compute method decorate with @api.depends(fields name) when this give field name is change then your compute method automatically call.

It's go to a loop because your compute method call write and your write method call compute method..

like 

Write     ⇄    Your compute method.

so remove  refresh() and add depends on your compute method.


Thank you.

1
Avatar
Abbandona
Samo Arko
Autore

Thanks for explaining why I get the error. But your tip won't work. The compute methods have already the depends of some fields, but they need data from 2 or 3 different models to correctly calculate values and those 2-3 models depend on a base calculation in the main model. The calculation is done in a editable one2many list so I can't get the values from other models, because the ids of my main model list data are new Objects. That is why I need to refresh the data when I save.

Jigar Vaghela (jva)

so u can add depends like sale.order_line.product_id.price so from your module to other model with many2one, one2many or many2many field. in sort you need relation with other model. if not directly connection then by pass like i do.

sale order to product_price

sale.order_line.product_id.price

so do depends like this

Samo Arko
Autore

thanks, didn't know that you could use depends on relations. will try to use it, but first I have to figure out what should depend on what in the main model and make a plan... a lot of lines of code .

Jigar Vaghela (jva)

Good :+1

Samo Arko
Autore

Nope... it won't work with depends because as soon as a computed field needs a value from child model it fails because of the PoS odoo.models.NewId. I added a button to the view that triggers the refresh method and everything works perfectly. But it's an annoying step for the user! It's really annoying that I can't do this with the save button!

Jigar Vaghela (jva)

you can do it from write but not directly you need to apply some trick.

so first in your ir.actions.act_window pass context like this

<record id="action_parent_model_form" model="ir.actions.act_window">

<field name="name">ParentModel</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">parent.model</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form</field>

<field name="context">{"update_compute":1}</field>

</record>

now do find this context in write like this

@api.multi

def write(self, vals):

record = super(ParentModel, self).write(vals)

if self._context.get('update_compute'):

for child in self.child_ids:

child.with_context({'update_compute': 0}).refresh()

Samo Arko
Autore

I thing you're a bit off the question. As I said if I call the method from the parent model it works, but calling it from the model where it is defined with write method doesn't work. The method is in the child model of the TOP parent, that child model has his own other child models.

Jigar Vaghela (jva)

then simple same do with child...like this.

@api.multi

def write(self, vals):

record = super(ParentModel, self).write(vals)

if self._context.get('update_compute'):

for child in self.child_ids:

child.with_context({'update_compute': 2}).refresh()

# method in child model that throws the error

@api.multi

def write(self, vals):

record = super(ChildModel, self).write(vals)

if self._context.get('update_compute') == 2:

self.refresh()

Samo Arko
Autore

mate thanks for all your help but this just doesn't want to work. With this it's just the same as without the context. it runs in a infinite loop.

Avatar
Ibrahim Boudmir
Risposta migliore

Hello samo,

"..Maximum recursion depth.."  happens because your function calls the Write (...) function and is declared inside Write (...)!

Moreover, the performance is so poor because you try to loop on self twice!! 

What i suggest is that you pass record and vals to your function refresh() and update vals with the data you need.
It should be like this : 

def write(self, vals):
for record in self:  
record.refresh(record, vals)
return super(YourClass, self).write(vals)
and your refresh would be : 
def refresh(self, record, vals): 
# your cases and update vals each time u want to consider datas changes.  
# For ex: vals['my_field'] = record.field 
# you did not show what your two other functions contain but i think you'll need to pass  
# these arguments too to _method1() function. For the other one, it should be declared outside. Somthing like:  @api.depends('')
def _computed_method1(self):
 for rec in self:  
# your process here
0
Avatar
Abbandona
Samo Arko
Autore

thanks for telling me what my code does, but I can't use your suggestion. The data that I refresh are in 2-3 other models and some of the fields in the main model are dependent on the values that are computed in the 2-3 other models. And I'm doing live calc on a one2many list, like a excel table, so I can't change/get data by relations because the list ids are newObjects.

Avatar
BISSTECH SRL
Risposta migliore

Hi Samo,

in your write method, try to call refresh on super, in the same way you do it for write.
Best,
Ioan

super(YourClass, self).refresh()

0
Avatar
Abbandona
Samo Arko
Autore

Thanks for trying to help but it doesn't work. It throws an attribute error. AttributeError: 'super' object has no attribute 'refresh'

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
One2many field odoo version 10
one2many odoo10
Avatar
Avatar
1
set 22
2847
Values has false in one2many field when changing the customer in Sale Order ODOO 10
one2many sale.order.line odoo10
Avatar
0
mar 23
6005
Prevent create and delete on a One2many tree view Risolto
treeview one2many odoo10
Avatar
1
lug 20
9403
Update a field in all One2many lines when a line is added or removed
one2many onchange odoo10
Avatar
0
apr 20
4954
How to search for records that have child records in One2many relation? Risolto
one2many search odoo10
Avatar
Avatar
1
gen 20
4410
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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