Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2340 Переглядів

When I create a compute field in odoo i Got below error,

Error:
Odoo Server Error

Traceback (most recent call last):
File "/opt/odoo/odoo/tools/safe_eval\\.py",\\ line\\ 354,\\ in\\ safe_eval
\\ \\ \\ \\ return\\ unsafe_eval\\(c,\\ globals_dict,\\ locals_dict\\)
\\ \\ File\\ "",\\ line\\ 3,\\ in\\
NameError:\\ name\\ 'Warning'\\ is\\ not\\ defined

During\\ handling\\ of\\ the\\ above\\ exception,\\ another\\ exception\\ occurred:

Traceback\\ \\(most\\ recent\\ call\\ last\\):
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 624,\\ in\\ _handle_exception
\\ \\ \\ \\ return\\ super\\(JsonRequest,\\ self\\)\\._handle_exception\\(exception\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 310,\\ in\\ _handle_exception
\\ \\ \\ \\ raise\\ pycompat\\.reraise\\(type\\(exception\\),\\ exception,\\ sys\\.exc_info\\(\\)\\[2\\]\\)
\\ \\ File\\ "/opt/odoo/odoo/tools/pycompat\\.py",\\ line\\ 14,\\ in\\ reraise
\\ \\ \\ \\ raise\\ value
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 669,\\ in\\ dispatch
\\ \\ \\ \\ result\\ =\\ self\\._call_function\\(\\*\\*self\\.params\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 350,\\ in\\ _call_function
\\ \\ \\ \\ return\\ checked_call\\(self\\.db,\\ \\*args,\\ \\*\\*kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/service/model\\.py",\\ line\\ 94,\\ in\\ wrapper
\\ \\ \\ \\ return\\ f\\(dbname,\\ \\*args,\\ \\*\\*kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 339,\\ in\\ checked_call
\\ \\ \\ \\ result\\ =\\ self\\.endpoint\\(\\*a,\\ \\*\\*kw\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 915,\\ in\\ __call__
\\ \\ \\ \\ return\\ self\\.method\\(\\*args,\\ \\*\\*kw\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 515,\\ in\\ response_wrap
\\ \\ \\ \\ response\\ =\\ f\\(\\*args,\\ \\*\\*kw\\)
\\ \\ File\\ "/mnt/extra\\-addons/ks_list_view_manager/controllers/lvm_controller\\.py",\\ line\\ 16,\\ in\\ call_kw
\\ \\ \\ \\ call_kw_result\\ =\\ super\\(LvmController,\\ self\\)\\.call_kw\\(model,\\ method,\\ args,\\ kwargs,\\ path\\)
\\ \\ File\\ "/opt/odoo/odoo/http\\.py",\\ line\\ 515,\\ in\\ response_wrap
\\ \\ \\ \\ response\\ =\\ f\\(\\*args,\\ \\*\\*kw\\)
\\ \\ File\\ "/opt/odoo/odoo/addons/web/controllers/main\\.py",\\ line\\ 1339,\\ in\\ call_kw
\\ \\ \\ \\ return\\ self\\._call_kw\\(model,\\ method,\\ args,\\ kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/addons/web/controllers/main\\.py",\\ line\\ 1331,\\ in\\ _call_kw
\\ \\ \\ \\ return\\ call_kw\\(request\\.env\\[model\\],\\ method,\\ args,\\ kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/api\\.py",\\ line\\ 387,\\ in\\ call_kw
\\ \\ \\ \\ result\\ =\\ _call_kw_multi\\(method,\\ model,\\ args,\\ kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/api\\.py",\\ line\\ 374,\\ in\\ _call_kw_multi
\\ \\ \\ \\ result\\ =\\ method\\(recs,\\ \\*args,\\ \\*\\*kwargs\\)
\\ \\ File\\ "/opt/odoo/odoo/models\\.py",\\ line\\ 6255,\\ in\\ onchange
\\ \\ \\ \\ for\\ name\\ in\\ nametree
\\ \\ File\\ "/opt/odoo/odoo/models\\.py",\\ line\\ 6256,\\ in\\
\\ \\ \\ \\ if\\ name\\ not\\ in\\ done\\ and\\ snapshot0\\.has_changed\\(name\\)
\\ \\ File\\ "/opt/odoo/odoo/models\\.py",\\ line\\ 6101,\\ in\\ has_changed
\\ \\ \\ \\ return\\ self\\[name\\]\\ !=\\ record\\[name\\]
\\ \\ File\\ "/opt/odoo/odoo/models\\.py",\\ line\\ 5731,\\ in\\ __getitem__
\\ \\ \\ \\ return\\ self\\._fields\\[key\\]\\.__get__\\(self,\\ type\\(self\\)\\)
\\ \\ File\\ "/opt/odoo/odoo/fields\\.py",\\ line\\ 1032,\\ in\\ __get__
\\ \\ \\ \\ self\\.compute_value\\(recs\\)
\\ \\ File\\ "/opt/odoo/odoo/fields\\.py",\\ line\\ 1146,\\ in\\ compute_value
\\ \\ \\ \\ records\\._compute_field_value\\(self\\)
\\ \\ File\\ "/opt/odoo/odoo/models\\.py",\\ line\\ 4005,\\ in\\ _compute_field_value
\\ \\ \\ \\ field\\.compute\\(self\\)
\\ \\ File\\ "/opt/odoo/odoo/addons/base/models/ir_model\\.py",\\ line\\ 33,\\ in\\
\\ \\ \\ \\ func\\ =\\ lambda\\ self:\\ safe_eval\\(text,\\ SAFE_EVAL_BASE,\\ \\{'self':\\ self\\},\\ mode="exec"\\)
\\ \\ File\\ "/opt/odoo/odoo/tools/safe_eval\\.py",\\ line\\ 377,\\ in\\ safe_eval
\\ \\ \\ \\ pycompat\\.reraise\\(ValueError,\\ ValueError\\('%s:\\ "%s"\\ while\\ evaluating\n%r'\\ %\\ \\(ustr\\(type\\(e\\)\\),\\ ustr\\(e\\),\\ expr\\)\\),\\ exc_info\\[2\\]\\)
\\ \\ File\\ "/opt/odoo/odoo/tools/pycompat\\.py",\\ line\\ 13,\\ in\\ reraise
\\ \\ \\ \\ raise\\ value\\.with_traceback\\(tb\\)
\\ \\ File\\ "/opt/odoo/odoo/tools/safe_eval\\.py",\\ line\\ 354,\\ in\\ safe_eval
\\ \\ \\ \\ return\\ unsafe_eval\\(c,\\ globals_dict,\\ locals_dict\\)
\\ \\ File\\ "",\\ line\\ 3,\\ in\\
ValueError:\\ :\\ "name\\ 'Warning'\\ is\\ not\\ defined"\\ while\\ evaluating
"for\\ rec\\ in\\ self:\n\\ \\ if\\ rec\\.date_time\\ >\\ datetime.datetime.now():\n raise Warning('blah blah blah')"

If I use automated action it work perfectly

Аватар
Відмінити
Найкраща відповідь

Hii JNZ,


You cannot raise warnings from UI while computing the field as exception modules(Warnings,UserError, ValidationError) are not predefined there.
The only predefined modules/variables are:
self (the set of records to compute)
datetime (Python module)
dateutil (Python module)
time (Python module)

->Instead of using compute or automated action,you can use user defined constraints to raise exceptions from your code.
You have to import the exception module and then write your function.
Here is the code:

from odoo.exceptions import ValidationError

@api.constrains('date_time')
def _check_date_time(self):
for rec in self:
if rec.date_time > datetime.datetime.now():
raise ValidationError(_(
"Your Message."
))


Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
черв. 25
15406
3
квіт. 25
5597
0
жовт. 24
1462
Compute Fields Вирішено
2
лип. 24
2875
1
січ. 24
1842