تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
8950 أدوات العرض

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. 


الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
الكاتب

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.

الكاتب أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
4
مايو 21
28967
0
يوليو 20
3069
1
يونيو 23
2494
3
فبراير 22
11175
1
مايو 21
4898