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

How and when we can use these methods ? Is there any tutorial to find about this?

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

Hi Shivam Mahajan

That's an internal model methods of the ORM and I don't know if you could find info out there about it. I will try to explain it to you so you could get an idea of how to use it

The __init__ method is used like usually in python for object initialization and for Odoo it's mostly used in report parsers to bring more data or custom functions or behaviors to the report templates(apply to those kind of objects that need an initialization to be used latter, report parsers in Odoo match that). You could read more about that here:

https://www.odoo.com/es_ES/forum/ayuda-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

The init method is used mostly for model initialization or database operations after the module is installed or updated, it's like a hook that you could use it for example(one of the most used scenario) to create an sql view for an analytic view report, normally used in combination with _auto = False on the model to don't trigger the database table creation for the model. As I said this method is only called(if defined) when the module is installed or updated, if you need a hook to initialize something more of your model you could define the method _register_hook that will be called after the models are loaded on the Odoo registry/pool of models

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

Thanks a lot Axel for sharing the Knowledge .I am really thankful to you .

Happy to help!!

الكاتب

How can we use the current user id in init() method because it takes only two parameters

init(self,cr)

There is no current user since it's a method called internally by the ORM after the module is installed, normally it's the admin

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مايو 25
647
0
يناير 24
1413
2
مايو 23
8252
5
ديسمبر 21
16327
0
ديسمبر 20
4458