Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4282 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
oct. 20
3336
2
iul. 24
2538
2
aug. 25
2538
1
iul. 25
957
1
aug. 25
1151