14

My task: a dynamic progress bar in odoo.

I'm using the Odoo widget: '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.

 @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?

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 -.-

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:

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:

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

odoo.logout()
IstaLibera
  • 580
  • 5
  • 22
  • progress bar field is a computed field right? Then why we need to update always – Hilar AK Sep 06 '17 at 03:39
  • Have a look here git@github.com:CybroOdoo/CybroAddons.git#10.0 – Hilar AK Sep 06 '17 at 03:41
  • no, the progress bar field (value) is not a computed field. It's updated via RPC calling the `updatevalue` method. Which of the CybroOdoo Addons are you referring to? – IstaLibera Sep 06 '17 at 05:55

1 Answers1

2

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. 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. 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]()

How do you define the percentage of completion of your process?

George Daramouskas
  • 3,720
  • 3
  • 22
  • 51
  • Thank you for your help! However, I don't know how to include the functions you mention to my model. Can you please help me - I updated my question for the specific workflow I have so far. Also I'm not so familiar with programming in javascript, so it would be really nice of you if you add code matching to my samle. – IstaLibera Sep 06 '17 at 11:38
  • the percentage of completion of my process is defined by the number of steps that are already fullfilled. Eg. the task has to do 20 steps - and 15 steps are complete -> the percentage of completion is 75%. But that's sth I just know outside of odoo -> hence I update the value with RPC calls. – IstaLibera Sep 11 '17 at 13:32