summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2019-01-24 15:59:20 +0000
committerNicolas Lempereur <nle@odoo.com>2019-01-24 16:18:19 +0000
commitce6e66cef930a30d9a62988a16f9f8319cb9f25c (patch)
treedbaa3d49b1954017f2e51caa6313e84428c883b5 /addons
parentb42cd64ace5f859184b8cc47a0db0963c03ae73b (diff)
[FIX] web: bar chart no crazy with 2 group by
In 3d2ca8104e4 some change were introduced to the graph view. But part of it had no sense when displaying data over 2 group by. eg. if the first level has 2 groups (2018, 2019) and each second level 2 groups (Done,Cancelled), we could have: 2018/Done: 0 2018/Cancelled: 5 2019/Done: 8 2019/Cancelled: 9 this gives us two main groups [2018: 5] / [2019: 17], the code remove the 2018 because [2018/Done] is 0 so we have something odd with columns not in order, and in stacked bar chart some part of a bar at the wrong offset opw-1932517 closes #30529
Diffstat (limited to 'addons')
-rw-r--r--addons/web/controllers/main.py23
-rw-r--r--addons/web/static/src/js/views/graph/graph_renderer.js10
-rw-r--r--addons/web/tests/__init__.py1
-rw-r--r--addons/web/tests/test_image.py19
4 files changed, 36 insertions, 17 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index d83e4f36f88..74c936ed73b 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1088,10 +1088,17 @@ class Binary(http.Controller):
height = int(height or 0)
width = int(width or 0)
+ if not content:
+ content = base64.b64encode(self.placeholder(image='placeholder.png'))
+ headers = self.force_contenttype(headers, contenttype='image/png')
+ if not (width or height):
+ suffix = field.split('_')[-1]
+ if suffix in ('small', 'medium', 'big'):
+ content = getattr(odoo.tools, 'image_resize_image_%s' % suffix)(content)
+
if crop and (width or height):
content = crop_image(content, type='center', size=(width, height), ratio=(1, 1))
-
- elif content and (width or height):
+ elif (width or height):
if not upper_limit:
# resize maximum 500*500
if width > 500:
@@ -1102,17 +1109,7 @@ class Binary(http.Controller):
encoding='base64', upper_limit=upper_limit,
avoid_if_small=avoid_if_small)
- if content:
- image_base64 = base64.b64decode(content)
- else:
- suffix = field.split('_')[-1]
- if suffix in ('small', 'medium', 'big'):
- encoded_placeholder = base64.b64encode(self.placeholder(image='placeholder.png'))
- image_base64 = base64.b64decode(getattr(odoo.tools, 'image_resize_image_%s' % suffix)(encoded_placeholder))
- else:
- image_base64 = self.placeholder(image='placeholder.png') # could return (contenttype, content) in master
- headers = self.force_contenttype(headers, contenttype='image/png')
-
+ image_base64 = base64.b64decode(content)
headers.append(('Content-Length', len(image_base64)))
response = request.make_response(image_base64, headers)
response.status_code = status
diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js
index 5ec89635dc8..2771159ab19 100644
--- a/addons/web/static/src/js/views/graph/graph_renderer.js
+++ b/addons/web/static/src/js/views/graph/graph_renderer.js
@@ -193,10 +193,12 @@ return AbstractRenderer.extend({
}
}
- // For Bar chart View, we keep only groups where count > 0
- data[0].values = _.filter(data[0].values, function (elem, index) {
- return self.state.data[index].count > 0;
- });
+ // For one level Bar chart View, we keep only groups where count > 0
+ if (this.state.groupedBy.length <= 1) {
+ data[0].values = _.filter(data[0].values, function (elem, index) {
+ return self.state.data[index].count > 0;
+ });
+ }
var $svgContainer = $('<div/>', {class: 'o_graph_svg_container'});
this.$el.append($svgContainer);
diff --git a/addons/web/tests/__init__.py b/addons/web/tests/__init__.py
index ffa03b739d9..1ed329bafe1 100644
--- a/addons/web/tests/__init__.py
+++ b/addons/web/tests/__init__.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from . import test_image
from . import test_js
from . import test_menu
from . import test_serving_base
diff --git a/addons/web/tests/test_image.py b/addons/web/tests/test_image.py
new file mode 100644
index 00000000000..96e09444c05
--- /dev/null
+++ b/addons/web/tests/test_image.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import io
+
+from PIL import Image
+
+from odoo.tests.common import HttpCase
+
+
+class TestImage(HttpCase):
+ def test_01_content_image_resize_placeholder(self):
+ response = self.url_open('/web/image/0/200x150')
+ image = Image.open(io.BytesIO(response.content))
+ self.assertEqual(image.size, (200, 150))
+
+ response = self.url_open('/web/image/fake/0/image_small')
+ image = Image.open(io.BytesIO(response.content))
+ self.assertEqual(image.size, (64, 64))