Hi all,
Can some help to setup communication between server and client, where I want to update the standard progresBarField in real-time:
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { patch } from "@web/core/utils/patch";
import { ProgressBarField } from "@web/views/fields/progress_bar/progress_bar_field";
const fieldRegistry = registry.category("fields");
console.log("Progress listener setup");
patch(ProgressBarField.prototype, {
setup() {
super.setup();
console.log("Setup progress bar");
this.busService = this.env.services.bus_service;
console.log("busService active is %B", this.busService.isActive);
this.channel = "progress_bar_channel";
this.busService.addChannel(this.channel);
this.busService.addEventListener("notification", this.onBusMessage.bind(this));
},
onBusMessage({detail: notifications}) {
console.log("onBusMessage", notifications);
notifications = notifications.filter(item => item.type === 'notification')
notifications.forEach(item => {
console.log("Progress: %d on field %s", item.payload.progress, item.payload.field);
this.setProgress(item.payload.field, item.payload.progress);
})
},
setProgress(fieldName,newProgress) {
if (newProgress >= 0 && newProgress <= 100) { // Ensure the progress is within bounds
console.log("newProgress", newProgress);
let value = String(newProgress);
this.onValueChange(value, fieldName);
}
}
});
At the Odoo server side I send progress information from a Model in Python as follows:
class MyImportWizard(models.TransientModel):
_name = 'myapp.import.wizard'
_description = 'Import Wizard '
_inherit = ['bus.listener.mixin'] # Inherit the mixin for bus notifications
file = fields.Binary("Select File", required=True, file_name = fields.Char()
progress = fields.Integer(string="Progress", default=0)
def import_file(self):
records = self.env['myapp.data'].search([])
rows_to_process = records.__len__()
rows_processed = 0
for record in records:
.... # Do some model and other model and database update work
rows_processed = rows_processed + 1
self.progress = (int)((rows_processed * 100) / rows_to_process)
self.env['bus.bus']._sendone('progress_bar_channel', 'notification',
{'field': 'progress','progress': self.progress})
self.env.cr.commit(). # Needed in Odoo 17 to release (send) bus messages to the client
self.progress = 100 # Complete the task
self.env['bus.bus']._sendone('progress_bar_channel', 'notification',
{'field': 'progress', 'progress': self.progress})
What changed in Odoo 18, that this is not working anymore. I see a lot of guessing work and changes over the different Odoo versions, where the Bus (bus.bus) API changed from version to version. In Odoo 17 I see all the console messages in the browser. In both Odoo 17 and 18 the bus_service is seen as active.
Can someone provide a good and working example on how this should work for Odoo 18
Thanks for your help and I hope that the answer contributes to a better Odoo