简体   繁体   English

Odoo10 / Odoo11动态进度条 - 在python中触发javascript函数

[英]Odoo10/Odoo11 dynamic progressbar - trigger javascript function inside python

My task: a dynamic progress bar in odoo. 我的任务:odoo中的动态进度条。

I'm using the Odoo widget: 'progressbar'. 我正在使用Odoo小部件:'progressbar'。 I want to update the view every time the value is updated - hence I want to trigger the on_change_input javascript function inside my python write method to render the view. 我想在每次更新值时更新视图 - 因此我想在我的python write方法中触发on_change_input javascript函数来呈现视图。

 @api.one
 def updatevalue(self, val):
      self.value = val
      # TODO call javascript function on_change_input()

The purpose is, that the progressbar should be updated while a process is running and the user should see the progress without updating the site. 目的是,在进程运行时应更新进度条,用户应该在不更新站点的情况下查看进度。

Is my task possible with the progressbar widget? 我的任务是否可以使用进度条小部件? Or is there another possibility to show dynamic content in Odoo? 或者是否有其他可能在Odoo中显示动态内容?

If I use my updatevalue method as button, the progressbar is updated after clicking the button without calling the javascript function & without refreshing the page... but I do want to call the method in my code (and probably over rpc) therefore this does not help -.- 如果我使用我的updatevalue方法作为按钮,单击按钮后更新进度条而不调用javascript函数并且不刷新页面...但我确实想在我的代码中调用该方法(并且可能在rpc上调用)因此这样做没有帮助-.-

Thank you for your time! 感谢您的时间!


Here is the workflow I have so far: 这是我到目前为止的工作流程:

The user clicks on the button do_time_consuming_task and the following function is called: 用户单击按钮do_time_consuming_task并调用以下函数:

def do_timeconsuming_task(self):
  ws = websocket.WebSocket()
  ws.connect('ws:/129.0.0.1:1234/')
  data = { 'topic' : 'server_command', 'id' : self.id, 'commandName' : 'do_sth',}
  payload = ujson.dumps(data)
  ws.send(payload)
  ws.close()

On the server, the command is received and processed. 在服务器上,接收并处理命令。 There is an open rpc connection: 有一个开放的rpc连接:

odoo = odoorpc.ODOO("129.0.0.1", port=8069)
odoo.login("database", "user", "password")
my_module = odoo.env['my_module.progress_widget_test']

progress_instance = my_module.browse(id)

Every time the progress value changes I call the following method of my module: 每次进度值更改时,我都会调用模块的以下方法:

progress_instance.updatevalue(new_value)

when the value equals 100 % I close the connection 当值等于100%时,我关闭连接

odoo.logout()

This functionality already exists and you can copy parts of it from account/static/src/js/account_reconciliation_widgets.js from the method updateProgressBar and processReconciliations . 此功能已存在,您可以从方法updateProgressBarprocessReconciliations复制account/static/src/js/account_reconciliation_widgets.js中的部分内容。 You will see here the correct way of updating the progress bar. 您将在此处看到更新进度条的正确方法。

The purpose is, that the progressbar should be updated while a process is running and the user should see the progress without updating the site. 目的是,在进程运行时应更新进度条,用户应该在不更新站点的情况下查看进度。

See on the processReconciliations how it is done, basically you call the process_reconciliations method that exists on the back end and you get a deferred object back. 请参阅processReconciliations它是如何完成的,基本上你调用后端存在的process_reconciliations方法,然后你得到一个deferred对象。 From that deferred object you can use progress() 从该延迟对象,您可以使用进度()

Looking through the documentation of .progress() you will see that you need to report your progress using .[notify][2]() 查看.progress()的文档,您将看到需要使用.[notify][2]()报告您的进度.[notify][2]()

How do you define the percentage of completion of your process? 你如何定义你的过程完成的百分比是多少?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM