Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

"RuntimeError: maximum recursion depth exceeded in cmp" problem

Subscribe

Get notified when there's activity on this post

This question has been flagged
one2manyodoo10
4 Replies
12089 Views
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
Discard
Avatar
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
Avatar
Discard
Samo Arko
Author

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
Author

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
Author

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
Author

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
Author

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
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
Avatar
Discard
Samo Arko
Author

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
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
Avatar
Discard
Samo Arko
Author

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!

Sign up
Related Posts Replies Views Activity
One2many field odoo version 10
one2many odoo10
Avatar
Avatar
1
Sep 22
2868
Values has false in one2many field when changing the customer in Sale Order ODOO 10
one2many sale.order.line odoo10
Avatar
0
Mar 23
6020
Prevent create and delete on a One2many tree view Solved
treeview one2many odoo10
Avatar
1
Jul 20
9416
Update a field in all One2many lines when a line is added or removed
one2many onchange odoo10
Avatar
0
Apr 20
4964
How to search for records that have child records in One2many relation? Solved
one2many search odoo10
Avatar
Avatar
1
Jan 20
4421
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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