使用execjs

时间:2018-05-09 09:19:34

标签: javascript python odoo execjs

我正在尝试创建一个在特定日期提醒用户的预定警报框。所以我安装了execjs并创建了这个方法:

import execjs

class Project(models.Model):
    _inherit = 'project.project'

    @api.multi
    def alert(self):
        js = """ alert("Hello World!!") """
        execjs.eval(js)

但是当我运行此方法时出现此错误:

2018-05-09 09:00:49,302 6508 ERROR erp_invoicefr odoo.addons.base.ir.ir_cron: Call of self.env[u'project.project'].alert(*()) failed in Job #8
Traceback (most recent call last):
File "D:\Projet\201802_invoicefr\odoo\addons\base\ir\ir_cron.py", line 126, in _callback
getattr(model, method_name)(*args)
File "D:\Projet\201802_invoicefr\invoicefr_addons\invoicefr_project\models\project_project.py", line 90, in alert
execjs.eval(js)
File "C:\Python27\lib\site-packages\execjs\__init__.py", line 51, in eval
return get().eval(source, cwd)
File "C:\Python27\lib\site-packages\execjs\_abstract_runtime.py", line 25, in eval
return self.compile('', cwd=cwd).eval(source)
File "C:\Python27\lib\site-packages\execjs\_abstract_runtime_context.py", line 27, in eval
return self._eval(source)
File "C:\Python27\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
return self.exec_(code)
File "C:\Python27\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
return self._exec_(source)
File "C:\Python27\lib\site-packages\execjs\_external_runtime.py", line 88, in _exec_
return self._extract_result(output)
File "C:\Python27\lib\site-packages\execjs\_external_runtime.py", line 167, in _extract_result
raise ProgramError(value)
ProgramError: ReferenceError: alert is not defined

0 个答案:

没有答案