Skip to Content
Menú
This question has been flagged
1 Respondre
4317 Vistes

Hi Everyone,


I'm trying to inherit odoo base function write_header which is defined inside BaseModel.


I've tried serveral examples but didn't helped, I also tried the following example which was succeded in earlier version of odoo.

from odoo.models import BaseModel

My TestClass(BaseModel)
def call_my_function(self):

print ("Triggered")

1/0

BaseModel.write_header = call_my_function

Any help is appriciated.


BR,

Vishnu

Avatar
Descartar
Best Answer

Hi Vishnu,

A few comments about your code


1) your class declaration is missing the class keyword and the class name has a space (which is forbidden), try something like

class MyTestClass

2) When using the Odoo ORM, inheritance also requires a line after the class declaration such as

_inherit = 'base'

3) While the last line will succeed in changing the behavior of BaseModel.write_header, this is not proper inheritance but rather monkey-patching. The difference is you're changing the behavior of the BaseClass instead of creating a new sub-class with a different behavior. For proper inheritance, re-define the method like

def write_header(self): # Note: keep same method signature
    your_code_here_ideally_not_dividing_by_zero


Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
d’oct. 20
3372
2
de jul. 24
2553
2
d’ag. 25
2595
1
de jul. 25
1000
1
d’ag. 25
1151