[IMP] web: sample data: generate better activities

The SampleServer picks a random value for selection fields. As a
consequence, field 'activity_exception_decoration' is always set,
either to 'warning' or 'danger'. When this field is set, widget
'ListActivity' (set on 'activity_ids') displays 'Warning', whatever
the value of 'activity_ids'. This means that with sample data, the
next activity field always displays "Warning", which is not great.

This special case has been handled in web, as it is the first (and
only) one. In the future, if we have to implement several special
cases like that, we'll setup a proper hook to allow external
modules to define them from the outside.

Task 2316726

closes odoo/odoo#55703

Signed-off-by: Mathieu Duckerts-Antoine <Polymorphe57@users.noreply.github.com>
This commit is contained in:
Aaron Bohy
2020-08-12 10:07:32 +00:00
parent d761a73ad0
commit d0bf6192d2
@@ -254,6 +254,15 @@ odoo.define('web.SampleServer', function (require) {
return [...new Set(ids)];
}
case "selection": {
// I hoped we wouldn't have to implement such special cases, but here it is.
// If this (mail) field is set, 'Warning' is displayed instead of the last
// activity, and we don't want to see a bunch of 'Warning's in a list. In the
// future, if we have to implement several special cases like that, we'll setup
// a proper hook to allow external modules to define extensions of this function.
// For now, as we have only one use case, I guess that doing it here is fine.
if (fieldName === 'activity_exception_decoration') {
return false;
}
if (field.selection.length > 0) {
return this._getRandomArrayEl(field.selection)[0];
}