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

Hi,


Need Help, In Python Code of my scheduled action, I am calling a simple method but it is not running as I want it to.


This is my code.


Scheduled Action Python Code:


model.my_method ()


My Model Python Code:


from odoo import fields, models, api, _

from odoo.exceptions import ValidationError


class MyNewModel (models.Model):

    _name = "my.newmodel"

    _description = "My New Model"


    @ api.model

    def my_method (self):

        try:

            raise ValidationError (_ ('Code IS Working'))

        except:

            raise ValidationError (_ ('Code IS NOT Working'))


When I manually run the scheduled action, this always gives me a ValidationError pop-up "Code IS NOT Working" instead of "Code IS Working". If I remove try except from my_method () and then manually run the scheduled action then I don't receive any error and nothing happens. Any idea why this is happening? Also one more thing, where can I view error logs in oddo which might occur after running this code?


Note: I can assure you that there are no indentation or spelling or extra space mistakes in my code.

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

Hi ,

Error Exceptions won't consider in Scheduled Actions. Here ValidationError in try block does not work as its a Exception raise , that's why except block handles that .



Hope it Helps 

Kiran K



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

Thanks Kiran Mohan. That clears things :)

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
يوليو 24
5542
0
أكتوبر 17
3020
3
فبراير 23
8102
5
ديسمبر 23
21075
1
فبراير 24
3938