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

There is an option in the menifest file to call method during module installation. We can mention pre_init and post_init. 

I would like to call one method while upgrading the module as similar to pre_init. because after module gets installed pre_init will not be called. 

Any suggestion for this ?

Why I need this ... 

I have a stored procedure to generate report data quickly which uses postgresql stored procedure, now when there is a slight change in the procedure I would like to update it thourh the module upgrade process. 


There should be some option available to call method during module upgrade as like pre_init and post_init. 


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

You can call any method during module update by adding function tag in the xml file.

# Add following code in XML file
<function model="sale.order" name="action_custom_method"/>

@api.model
def action_custom_method(self):
# Your code goes here...
return True

This way method will be called after you upgrade the module.

Ảnh đại diện
Huỷ bỏ
Tác giả

Yes, it make sense, I will try it and let you know. But isn't there any option to call method during update as like pre_init? I am wondering, it should be there.

AFAIK I have never seen such thing for module update. Still, I am not 100% sure.

Tác giả Câu trả lời hay nhất

Finally, I got the solution.


We created one .sql file and into that file we added all our stored procedures and other database objects.


We added that sql file in the __manifest__.py


'data': [            
            'db_function/get_product_sales_history_data.sql',
            'db_function/update_product_sales_history.sql',
        ],

It will execute these sql files at the time of module installation as well as module upgrade time.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 5 21
28947
0
thg 7 20
3055
1
thg 6 23
2473
3
thg 2 22
11160
1
thg 5 21
4890