[FIX] web: graph view ignores duplicate labels

Steps to reproduce:
- install recruitment
- go to recruitment > configuration > job positions > duplicate a job
and keep the exact same name as the original > change the department
- add any application to the newly created job position
- go to recruitment > applications > all applications > select the
graph view > group by job

Previous behavior:
you only see one of the two jop positions with the same name
the graph view does not handle multiple labels with the same name
and only keeps the latest values when rendering

Current behavior:
duplicate labels are suffixed to prevent the view from confusing them

opw-2214284

closes odoo/odoo#47948

X-original-commit: a77086f8bcb4498361d1183ba8af3d0663cd031b
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: mightyjol <jhk-odoo@users.noreply.github.com>
This commit is contained in:
jerome hanke (jhk)
2020-03-18 17:22:59 +00:00
parent 20e713bb27
commit e58db3ff5c
2 changed files with 10 additions and 4 deletions
@@ -242,6 +242,7 @@ return AbstractModel.extend({
value = 1;
}
self.chart.dataPoints.push({
resId: dataPt[self.chart.groupBy[0]] instanceof Array ? dataPt[self.chart.groupBy[0]][0] : -1,
count: count,
value: value,
labels: labels,
@@ -622,13 +622,19 @@ return AbstractRenderer.extend({
_prepareData: function (dataPoints) {
var self = this;
var labelMap = {};
var labels = dataPoints.reduce(
function (acc, dataPt) {
var label = self._getLabel(dataPt);
var index = self._indexOf(acc, label);
if (index === -1) {
var labelKey = dataPt.resId + ':' + JSON.stringify(label);
var index = labelMap[labelKey];
if (index === undefined) {
labelMap[labelKey] = dataPt.labelIndex = acc.length;
acc.push(label);
}
else{
dataPt.labelIndex = index;
}
return acc;
},
[]
@@ -650,8 +656,7 @@ return AbstractRenderer.extend({
if (!(datasetLabel in acc)) {
acc[datasetLabel] = newDataset(datasetLabel, dataPt.originIndex);
}
var label = self._getLabel(dataPt);
var labelIndex = self._indexOf(labels, label);
var labelIndex = dataPt.labelIndex;
acc[datasetLabel].data[labelIndex] = dataPt.value;
return acc;
},