Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2717 Vistas

In odoo v15

How can I create a custom widget for the fields in a tree view that also work when the lines are grouped? 

I managed to create the custom widget which I applied on a FloatField with a

group_operator="sum"

. However, when the lines of the tree view are grouped, it displays the sum without the format of the widget. How can I solve this? 

Here is the code for the widget (for a readonly field only):

odoo.define('test.timedelta_widget', function (require) {
"use strict";

var AbstractField = require('web.AbstractField');
var basic_fields = require('web.basic_fields');
var relational_fields = require('web.relational_fields');
var registry = require('web.field_registry');
var special_fields = require('web.special_fields');
var core = require('web.core');

var _t = core._t;
var _lt = core._lt;

const TimeDelta = basic_fields.NumericField.extend({
description: _lt("TimeDelta"),
supportedFieldTypes: ['float', 'integer'],

_renderReadonlyValue: function (value) {
return "hello3";
},
});

registry.add('timedelta', TimeDelta);
});

And the view is:

<tree string="Product" multi_edit="1" sample="1">
...
<field name="list_price" string="Sales Price" widget="timedelta"/>
...
< tree>


Avatar
Descartar
Mejor respuesta

Per _renderAggregateCells​ in addons/web/static/src/legacy/js/views/list/list_renderer.js, it looks like you need to add a format function for your widget to the format​ dictionary of addons/web/static/src/legacy/js/fields/field_utils.js

Avatar
Descartar