Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
8973 Lượt xem

I wanna change something in export_data function then I wanna override BaseModel class. But really don't know how to override this? I try to copy a file file orm.py and fix import but the it not call in side this file.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Dear Sir

it's not worked for me as seen this error

except_orm: ('ValueError', 'The class Extend_BaseModel has to have a _name attribute')

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

First you have to inherit the class BaseModel and then can override the method.

Try this:

class Extend_BaseModel(BaseModel):
    def export_data(self, cr, uid, ids, fields_to_export, context=None):
        #Your code
        #You may call super also if you want like this: super(Extend_BaseModel, self).export_data(cr, uid, ids, fields_to_export, context=context)
        #Your code

Hope this will help you and solve you problem.

Thanks,

Serpent Consulting Services.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I achieve overriding BaseModel methods in V7 :

1- create a new python file my_basemodel.py

2- add your custom methods like this

from openerp.osv.orm import BaseModel

def my_method(self, cr, uid, ids, context=None):

do_somthing

BaseModel.method = my_method    # Method is referring to an ORM methode (read, unlink, export_data, ...)

3- save the file and add it to __init__.py

4- Restart your server

Ảnh đại diện
Huỷ bỏ

this is called monkey patching, this way is not good. If we want to use monkey patching in Odoo. look into the hooks provided by odoo

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 11 24
30025
5
thg 8 24
2648
0
thg 1 22
2423
1
thg 12 21
2761
0
thg 12 21
2327