summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorXavier Bol (xbo) <xbo@odoo.com>2019-11-20 12:54:35 +0000
committerYannick Tivisse <yti@odoo.com>2020-01-21 09:22:46 +0000
commit51b36c3dbbce04ba6d459c8890f82ac3fdbd91bd (patch)
tree5ba445b8a98a0c6084904d0827d500a2dfc333c4 /addons
parentbe01db2f712952a6c1d3688c8587d9624ef5dcc5 (diff)
[IMP] base: add default image for users + placeholder if unassigned
1/ When the new database is created without demo data, the admin has a 'silhouette' as a default picture. When a new user is created without picture given by the current user, the new user will have a 'silhouette' as a default profile picture. 2/ web: image for fa-user-slash. This image will be used when a record is unassigned. 3/ web, *: Change placeholder by default when record is unassigned. We want to have a fa-user-slash icon when a record is unassigned instead of 'placeholder.png'. A method is created in the BaseModel to have a generic method to change easily the placeholder for other models. 4/ Adapt kanban test to keep the same behaviour. Attention the behaviour is a bit different. Because, now the default image is given by the server to change easily the default image when a record doesn't have an image. Thus, we don't say if it's the default placeholder, but we can say it's not the same image of the record (in this test, the record, it's the partner). 5/ misc: display 'Unassigned' in the hover on kanban cards if record is unassigned closes odoo/odoo#41356 Taskid: 2060206 Related: odoo/enterprise#7758 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com> Co-authored-by: jdoutreloux <jud@odoo.com> Co-authored-by: Yannick Tivisse <yti@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/account_analytic_default/views/account_analytic_default_view.xml3
-rw-r--r--addons/crm/views/crm_lead_views.xml6
-rw-r--r--addons/hr_recruitment/views/hr_recruitment_views.xml3
-rw-r--r--addons/maintenance/views/maintenance_views.xml3
-rw-r--r--addons/mass_mailing/views/mailing_mailing_views.xml3
-rw-r--r--addons/project/views/project_views.xml6
-rw-r--r--addons/purchase_requisition/views/purchase_requisition_views.xml3
-rw-r--r--addons/stock_picking_batch/views/stock_picking_batch_views.xml3
-rw-r--r--addons/web/controllers/main.py29
-rw-r--r--addons/web/static/src/js/views/kanban/kanban_record.js5
-rw-r--r--addons/web/static/tests/views/kanban_tests.js9
-rw-r--r--addons/website_slides/views/slide_slide_views.xml3
12 files changed, 53 insertions, 23 deletions
diff --git a/addons/account_analytic_default/views/account_analytic_default_view.xml b/addons/account_analytic_default/views/account_analytic_default_view.xml
index 805ec5250ca..bddeeaf80eb 100644
--- a/addons/account_analytic_default/views/account_analytic_default_view.xml
+++ b/addons/account_analytic_default/views/account_analytic_default_view.xml
@@ -59,7 +59,8 @@
<div t-attf-class="oe_kanban_card oe_kanban_global_click">
<div>
<strong><span><field name="analytic_id"/></span></strong>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover float-right"/>
</div>
<div t-if="record.date_start.value"><i class="fa fa-calendar"></i> From <field name="date_start"/> <t t-if="record.date_stop.value">to <field name="date_stop"/></t></div>
<div t-if="record.product_id.value"><strong>Product</strong> <field name="product_id"/> </div>
diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml
index aad23b2abb9..469661290ee 100644
--- a/addons/crm/views/crm_lead_views.xml
+++ b/addons/crm/views/crm_lead_views.xml
@@ -377,7 +377,8 @@
</div>
</div>
<div class="oe_kanban_bottom_right">
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
</div>
</div>
</div>
@@ -508,7 +509,8 @@
<field name="activity_ids" widget="kanban_activity"/>
</div>
<div class="oe_kanban_bottom_right">
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
</div>
</div>
</div>
diff --git a/addons/hr_recruitment/views/hr_recruitment_views.xml b/addons/hr_recruitment/views/hr_recruitment_views.xml
index 15f9c723a90..ea11d7f5e0e 100644
--- a/addons/hr_recruitment/views/hr_recruitment_views.xml
+++ b/addons/hr_recruitment/views/hr_recruitment_views.xml
@@ -329,7 +329,8 @@
<field name="legend_blocked" invisible="1"/>
<field name="legend_done" invisible="1"/>
</div>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
</div>
</div>
diff --git a/addons/maintenance/views/maintenance_views.xml b/addons/maintenance/views/maintenance_views.xml
index 17976dea62f..86209c2d090 100644
--- a/addons/maintenance/views/maintenance_views.xml
+++ b/addons/maintenance/views/maintenance_views.xml
@@ -164,7 +164,8 @@
</div>
<div class="oe_kanban_bottom_right">
<field name="kanban_state" widget="state_selection"/>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
</div>
</div>
</div>
diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml
index 5e8cfdb390e..c6fc0a3dc29 100644
--- a/addons/mass_mailing/views/mailing_mailing_views.xml
+++ b/addons/mass_mailing/views/mailing_mailing_views.xml
@@ -351,7 +351,8 @@
<field name='mailing_model_id' attrs="{'invisible': [('mailing_model_name','=','mailing.list')]}"/>
<span attrs="{'invisible': [('mailing_model_name','!=','mailing.list')]}">Mailing Contact</span>
</span>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="o_image_24_cover oe_kanban_avatar float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="o_image_24_cover oe_kanban_avatar float-right"/>
</div>
</div>
</t>
diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml
index a42c64e6c05..47573ae7024 100644
--- a/addons/project/views/project_views.xml
+++ b/addons/project/views/project_views.xml
@@ -256,7 +256,8 @@
</div>
<div class="col-4">
<div class="oe_kanban_bottom_right">
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover float-right"/>
</div>
</div>
</div>
@@ -660,7 +661,8 @@
</div>
<div class="oe_kanban_bottom_right" t-if="!selection_mode">
<field name="kanban_state" widget="state_selection" groups="base.group_user" invisible="context.get('fsm_mode', False)"/>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
</div>
</div>
</div>
diff --git a/addons/purchase_requisition/views/purchase_requisition_views.xml b/addons/purchase_requisition/views/purchase_requisition_views.xml
index 265a747b23f..3a18208b13e 100644
--- a/addons/purchase_requisition/views/purchase_requisition_views.xml
+++ b/addons/purchase_requisition/views/purchase_requisition_views.xml
@@ -244,7 +244,8 @@
<field name="vendor_id"/>
</div>
<div class="oe_kanban_bottom_right">
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar float-right"/>
</div>
</div>
</div>
diff --git a/addons/stock_picking_batch/views/stock_picking_batch_views.xml b/addons/stock_picking_batch/views/stock_picking_batch_views.xml
index a729315f9bd..24474a6e0b3 100644
--- a/addons/stock_picking_batch/views/stock_picking_batch_views.xml
+++ b/addons/stock_picking_batch/views/stock_picking_batch_views.xml
@@ -78,7 +78,8 @@
<div class="o_kanban_record_bottom">
<div class="oe_kanban_bottom_left"/>
<div class="oe_kanban_bottom_right">
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar"/>
</div>
</div>
</div>
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index cdc2fa3b950..3041058826b 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1367,7 +1367,8 @@ class Binary(http.Controller):
@staticmethod
def placeholder(image='placeholder.png'):
- with tools.file_open(get_resource_path('web', 'static/src/img', image), 'rb') as fd:
+ image_path = image.lstrip('/').split('/') if '/' in image else ['web', 'static', 'src', 'img', image]
+ with tools.file_open(get_resource_path(*image_path), 'rb') as fd:
return fd.read()
@http.route(['/web/content',
@@ -1437,23 +1438,35 @@ class Binary(http.Controller):
def _content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas',
filename_field='name', unique=None, filename=None, mimetype=None,
download=None, width=0, height=0, crop=False, quality=0, access_token=None,
- placeholder='placeholder.png', **kwargs):
+ placeholder=None, **kwargs):
status, headers, image_base64 = request.env['ir.http'].binary_content(
xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
filename_field=filename_field, download=download, mimetype=mimetype,
default_mimetype='image/png', access_token=access_token)
- return Binary._content_image_get_response(status, headers, image_base64, field=field, download=download,
- width=width, height=height, crop=crop, quality=quality,
- placeholder=placeholder)
+ return Binary._content_image_get_response(
+ status, headers, image_base64, model=model, id=id, field=field, download=download,
+ width=width, height=height, crop=crop, quality=quality,
+ placeholder=placeholder)
@staticmethod
- def _content_image_get_response(status, headers, image_base64, field='datas', download=None,
- width=0, height=0, crop=False, quality=0, placeholder='placeholder.png'):
+ def _content_image_get_response(
+ status, headers, image_base64, model='ir.attachment', id=None,
+ field='datas', download=None, width=0, height=0, crop=False,
+ quality=0, placeholder='placeholder.png'):
if status in [301, 304] or (status != 200 and download):
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if not image_base64:
- image_base64 = base64.b64encode(Binary.placeholder(image=placeholder))
+ if placeholder is None and model in request.env:
+ # Try to browse the record in case a specific placeholder
+ # is supposed to be used. (eg: Unassigned users on a task)
+ record = request.env[model].browse(int(id)) if id else request.env[model]
+ placeholder_filename = record._get_placeholder_filename(field=field)
+ placeholder_content = Binary.placeholder(image=placeholder_filename)
+ else:
+ placeholder_content = Binary.placeholder()
+ image_base64 = base64.b64encode(placeholder_content)
+
if not (width or height):
width, height = odoo.tools.image_guess_size_from_field_name(field)
diff --git a/addons/web/static/src/js/views/kanban/kanban_record.js b/addons/web/static/src/js/views/kanban/kanban_record.js
index ab19e73d2eb..f199a286db6 100644
--- a/addons/web/static/src/js/views/kanban/kanban_record.js
+++ b/addons/web/static/src/js/views/kanban/kanban_record.js
@@ -184,14 +184,13 @@ var KanbanRecord = Widget.extend({
* @returns {string} the url of the image
*/
_getImageURL: function (model, field, id, placeholder) {
- id = (_.isArray(id) ? id[0] : id) || false;
- placeholder = placeholder || "/web/static/src/img/placeholder.png";
+ id = (_.isArray(id) ? id[0] : id) || null;
var isCurrentRecord = this.modelName === model && this.recordData.id === id;
var url;
if (isCurrentRecord && this.record[field] && this.record[field].raw_value && !utils.is_bin_size(this.record[field].raw_value)) {
// Use magic-word technique for detecting image type
url = 'data:image/' + this.file_type_magic_word[this.record[field].raw_value[0]] + ';base64,' + this.record[field].raw_value;
- } else if (!model || !field || !id || (isCurrentRecord && this.record[field] && !this.record[field].raw_value)) {
+ } else if (placeholder && (!model || !field || !id || (isCurrentRecord && this.record[field] && !this.record[field].raw_value))) {
url = placeholder;
} else {
var session = this.getSession();
diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js
index 0b8334472ad..c0a07c699fa 100644
--- a/addons/web/static/tests/views/kanban_tests.js
+++ b/addons/web/static/tests/views/kanban_tests.js
@@ -5264,8 +5264,15 @@ QUnit.module('Views', {
return this._super.apply(this, arguments);
},
});
+ var images = kanban.el.querySelectorAll('img');
+ var placeholders = [];
+ for (var [index, img] of images.entries()) {
+ if (img.dataset.src.indexOf(this.data.partner.records[index].image) === -1) {
+ // Then we display a placeholder
+ placeholders.push(img);
+ }
+ }
- var placeholders = kanban.$('img[data-src$="/web/static/src/img/placeholder.png"]');
assert.strictEqual(placeholders.length, this.data.partner.records.length - 1,
"partner with no image should display the placeholder");
diff --git a/addons/website_slides/views/slide_slide_views.xml b/addons/website_slides/views/slide_slide_views.xml
index 0301710e345..1f98a26f89d 100644
--- a/addons/website_slides/views/slide_slide_views.xml
+++ b/addons/website_slides/views/slide_slide_views.xml
@@ -211,7 +211,8 @@
<t t-else=""><i class="fa fa-file-pdf-o mr-2" aria-label="Document" role="img" title="Document"/></t>
<field name="slide_type"/>
</span>
- <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover"/>
+ <t t-set="unassigned"><t t-esc="_t('Unassigned')"/></t>
+ <img t-att-src="kanban_image('res.users', 'image_128', record.user_id.raw_value)" t-att-title="record.user_id.value || unassigned" t-att-alt="record.user_id.value" class="oe_kanban_avatar o_image_24_cover"/>
</div>
</div>
</div>