Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
1339 Ansichten

I am developing a custom module and facing an issue like inheriting the Method without super call , and the flow of super breaks.


while in other module i have done the same and override without super some other method but it called the method from other modules that have extended the same 


So can anyone explain the sequence of method calling in odoo , i dont understand if i inherit a method without super , in one case it does not call any super method and in other case it calls , why ?????

Avatar
Verwerfen
Beste Antwort

I hope your idea will work. Although, I don't understand what custom module you are referring to.

Avatar
Verwerfen

Perform the following steps to call the action_confirm method of the education.application model:
Create file application_method.py. You can put this file anywhere you want because the RPC program will work independently.
Add the following code to the file:
from xmlrpc import client
server_url = 'http://localhost:8069'
db_name = 'viin_education'
username = 'admin'
password = 'admin'
common = client.ServerProxy('%s/xmlrpc/2/common' % server_url)
user_id = common.authenticate(db_name, username, password, {})
models = client.ServerProxy('%s/xmlrpc/2/object' % server_url)
if user_id:
# Create application with state draft
application_id = models.execute_kw(db_name, user_id, password,
'education.application', 'create',
[{'name': 'New application', 'application_date': '2022-01-18', 'admission_date': '2022-01-18', 'state': 'draft'}])
# Call action_confirm method on new application
models.execute_kw(db_name, user_id, password,
'education.application', 'action_confirm', [[application_id]])
# check application status after method call
application_data = models.execute_kw(db_name, user_id, password,
'education.application', 'read', [[application_id], ['name', 'state']])
print('Student state after method call:', application_data[0]['state'])
else:
print('Wrong credentials')
3.Run the Python script from Terminal with the following command:
python3 application_method.py
The program will create an enrollment profile with draft status and then we will change the status of the enrollment profile by calling action_confirm method. We will then read the admissions profile data to check the status of the admissions application, which will produce the following output:
application_id= 10
I hope it is information which you mention
https://hill-climbracing.com

Autor Beste Antwort

Yes , but i need to know that other methods that are extending the same method , with super are getting called in some case , and not in others !! why ?


Avatar
Verwerfen
Beste Antwort

Inheritance using super(): When you inherit a method and call super() within the overridden method, it allows you to extend or modify the behavior of the original method while still executing the code of the overridden method in the parent class. This ensures that the original functionality is preserved while adding your custom logic.

For example:

class MyModule(models.Model):
_inherit = 'some.other.module'

def my_method(self):
# Custom code before the super call
res = super(MyModule, self).my_method()
# Custom code after the super call
return res

  1. In this case, calling super() invokes the method in the parent class (the original method), and you can modify its behavior as needed.

  2. Inheritance without super(): If you inherit a method but do not include a super() call within the overridden method, the original method in the parent class will not be executed automatically. Instead, only the code within the overridden method will be executed.

    For example:


class MyModule(models.Model):
_inherit = 'some.other.module'

def my_method(self):
# Custom code without calling super()
return # No call to super()

In this case, the original method in the parent class will not be executed unless explicitly called within the overridden method.


Avatar
Verwerfen