I want to change the color of a progress bar that is in a one2many line in an Transient Model.
My idea was to create a custom widget from the progressbar widget and then add a method that gets the color value and the script changes the color.
The color value will be stored in a computed field that is invisible in the line.
So my first try was to create the custom widget, but that didn’t work.
odoo.define('your_module_name.custom_progressbar', function (require) {
"use strict";
var field_registry = require('web.field_registry');
var FieldProgressBar = require('web.basic_fields').FieldProgressBar;
var CustomProgressBar = FieldProgressBar.extend({
template: FieldProgressBar.prototype.template,
// Your custom methods and properties here
});
field_registry.add('custom_progressbar', CustomProgressBar);
return CustomProgressBar;
});
I am not very good at Java coding, and the web was no help in that case.
The problem is that I get a message in the browser dev tools:
web.assets_backend.min.js:2970 Missing widget: CustomProgressBar for field of type integer
At this point, I have not tried to make the part with the colors until the original widget is shown in my view.
and the widget is not shown.
And yes the .js is in manifast and will also run
Can someone help me with that?
2
Answers
So this is my latest code:
Now the problem I am trying to solve is that the function:
RenderElement() is not executed, I do not know why, so the color is not transferred to the progress bar.
But I am getting the correct value in the constructor().
of the template:
and the css to change the color:
Is there any good explanation for the js. part in odoo 16, thats not easy to understand the framework.
thanks
Try to inherit the progress bar field
Example:
You can use a custom template as follows:
To change field color based on a computed field, you can use the
t-attf-class
attribute: