Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

"RuntimeError: maximum recursion depth exceeded in cmp" problem

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
one2manyodoo10
4 Replies
12094 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Jigar Vaghela (jva)
Best Answer

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
Portretas
Atmesti
Samo Arko
Autorius

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
Autorius

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
Autorius

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
Autorius

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
Autorius

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.

Portretas
Ibrahim Boudmir
Best Answer

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
Portretas
Atmesti
Samo Arko
Autorius

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.

Portretas
BISSTECH SRL
Best Answer

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
Portretas
Atmesti
Samo Arko
Autorius

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

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

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

Registracija
Related Posts Replies Rodiniai Veikla
One2many field odoo version 10
one2many odoo10
Portretas
Portretas
1
rugs. 22
2870
Values has false in one2many field when changing the customer in Sale Order ODOO 10
one2many sale.order.line odoo10
Portretas
0
kov. 23
6024
Prevent create and delete on a One2many tree view Solved
treeview one2many odoo10
Portretas
1
liep. 20
9419
Update a field in all One2many lines when a line is added or removed
one2many onchange odoo10
Portretas
0
bal. 20
4966
How to search for records that have child records in One2many relation? Solved
one2many search odoo10
Portretas
Portretas
1
saus. 20
4427
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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