summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2017-10-23 11:53:29 +0200
committerLucas Perais (lpe) <lpe@odoo.com>2017-10-25 16:39:52 +0200
commitf45edfbe6d03b15977392dda9561cd7a3e16ce34 (patch)
treea55c431e5f5084c67cb45e5d4ae3bc9699e62abc /addons/web/static/src/js/fields/basic_fields.js
parent6fc0793c30705301190eb67558dab93da9d9424a (diff)
[FIX] web: image widget is dependent on its record's last_update
As a way to optimize loading, images are not necessarily fetched in db. They have, in their url a "unique" parameter, which is the last_update date on **the record** and controls on the python-side whether it should get the image from a cache or from the db. Before this commit, this __last_update field wasn't present in the view, so it wasn't fetched, and writes on a model's image worked but did not refresh. The image displayed was the old one. After this commit, when the image field widget is present, we force the loading of the __last_update field of the record. Upon update, the image displayed is the new one. OPW 777552 closes #20457
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 7a7b3fa370f..ce1a305277f 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -21,6 +21,7 @@ var framework = require('web.framework');
var session = require('web.session');
var utils = require('web.utils');
var view_dialogs = require('web.view_dialogs');
+var field_utils = require('web.field_utils');
var qweb = core.qweb;
var _t = core._t;
@@ -1127,6 +1128,10 @@ var AbstractFieldBinary = AbstractField.extend({
});
var FieldBinaryImage = AbstractFieldBinary.extend({
+ fieldDependencies: _.extend({}, AbstractFieldBinary.prototype.fieldDependencies, {
+ __last_update: {type: 'datetime'},
+ }),
+
template: 'FieldBinaryImage',
placeholder: "/web/static/src/img/placeholder.png",
events: _.extend({}, AbstractFieldBinary.prototype.events, {
@@ -1149,7 +1154,7 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
id: JSON.stringify(this.res_id),
field: this.nodeOptions.preview_image || this.name,
// unique forces a reload of the image when the record has been updated
- unique: (this.recordData.__last_update || '').replace(/[^0-9]/g, ''),
+ unique: field_utils.format.datetime(this.recordData.__last_update).replace(/[^0-9]/g, ''),
});
}
}