Odoo Help


How to call a method from other class?

Juan Formoso
on 12/9/14, 5:11 AM 6,883 views

I've created two new models: event.meeting and event.meeting.registration (this one has a column named meeting_id, which relates it to the first one).

In event.meeting, I've created a method named my_method (non-static). Now, I want to call it from a function of event.meeting.registration. And to do that, I did this:

for record in self.browse(cr, uid, ids, context=context):
    eve_mee_obj = self.pool.get('event.meeting')
    elements = eve_mee_obj.browse(cr, uid, [record.meeting_id], context=context)
    for element in elements:
        a = element.my_method(cr, uid, [record.meeting_id], context)
return False

But I'm getting this error:

TypeError: my_method() takes at most 5 arguments (9 given)

Can anyone help me, please?

can you please give my_method definition also?

Baiju KS
on 12/9/14, 5:28 AM

Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 12/9/14, 5:40 AM

If you are trying in odoo API:

You just need to call:

a = element.my_method()

Also in your code, a change is at "for element in elements:", not element in element, please change that also and try.

It is giving you a TypeError like that because, those arguements which you passing in that method call is passing implicitly in new API.

You can also get this in single line as using new API:

a = self.env['event.meeting'].browse([record.meeting_id.id]).my_method(). But then you don't need to use self.pool.get. If you want I can rewrite the code. You just try first one and if not getting, I will help you.


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 12/9/14, 5:40 AM


There is two way of method calling.

1) Using simple class object.

2) Using browse object of that class.

You are calling your method using 2nd way. So, you do not have to pass the cr, uid, ids. You just need to pass context if it is available into method defination.

So, you have to call your method like below.

element.my_method(context=context) or element.my_method()

I hope it helpful to you.

Thank you! I've got context, but I get the error if I try to pass it. Without any parameter, it works.

Juan Formoso
on 12/9/14, 7:03 AM

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 5 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 12/9/14, 5:51 AM

try this

for record in self.browse(cr, uid, ids, context=context):
    eve_mee_obj = self.pool.get('event.meeting')
    elements = eve_mee_obj.browse(cr, uid, [record.meeting_id], context=context)
    for element in elements:
        a =
eve_mee_obj.my_method(cr, uid, [record.meeting_id], context)
return False


In OpenERP 7, you have to call the function from object instantiation.
But this code works for Odoo 8 as function can be called from Object instance and record value.

Thank you! But that will only work if my method were static, won't it?

Juan Formoso
on 12/9/14, 6:48 AM

Is your working environment Version 7 or 8? If it is version 8, then check the odoo documentation for defining methods

Atchuthan - Technical Consultant, Sodexis Inc
on 12/9/14, 7:01 AM



| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 12/9/14, 5:37 AM

1. never fetch objects from within the loop...
--> always self.pool.get BEFORE the loop (inside loop will fetch the same object for every pass in loop)
2. [record.meeting_id] will be browse object
--> maybe you ment: [record.meeting_id.id] (wich will be actual id(s) of object)
3. elements got from eve_mee_obj is in fact one single element (providing single record.meeting_id -> no need for second for loop ) 
-> but do you realy need to browse it if you want to run a method from it?
so try like this:

eve_mee_obj = self.pool.get('event.meeting')
for record in self.browse(cr, uid, ids, context=context):

    a = eve_mee_obj.my_method(cr, uid, [record.meeting_id.id], context)
    # do something with a for each record


hope it helps : ) 


You're right, I had the pool inside the for and that's not a good idea. However, the method isn't static, so I can't call it from the class. I need to call it from the object. It can be done doing what Akhil P Sivan said. Anyway, thank you very much, your comment is useful.

Juan Formoso
on 12/9/14, 6:51 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 12/9/14, 5:11 AM
Seen: 6883 times
Last updated: 3/16/15, 8:10 AM