[FIX] base: update File Content for binary field

To distinguish two ir.attachment 'File Content', we base it on the file
size (this I imagine is for efficiency).

This is done by setting bin_size in the context. Doing this, the
returned db_datas field will be the file size of the converted to base64
content (if no filestore).

But this size is returned in string format, so "get_nice_size" (in
openerp/osv/fields.py) which gets this size calculates the length of the
string. e.g: if the size is '2142' get_nice_size will return 4.

This fix solves this by converting the string to an integer, thus
unifying it with the filestore case (where we use os.path.getsize which
return an integer).

Also, the field presenting the issue (FieldBinaryFile) has been changed
so it is always updated even if the size is the same (as it was already
done by 3632949 for FieldBinaryImage widget).

closes #7223
opw-643071
This commit is contained in:
Nicolas Lempereur 2015-06-23 11:46:20 +02:00
parent 6acd5ef91c
commit 1942522969
2 changed files with 14 additions and 0 deletions

View File

@ -5177,6 +5177,17 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
this._super.apply(this, arguments);
this.$el.find('input').eq(0).val('');
this.set_filename('');
},
set_value: function(value_){
var changed = value_ !== this.get_value();
this._super.apply(this, arguments);
// Trigger value change if size is the same
if (!changed){
this.trigger("change:value", this, {
oldValue: value_,
newValue: value_
});
}
}
});

View File

@ -132,6 +132,9 @@ class ir_attachment(osv.osv):
result[attach.id] = self._file_read(cr, uid, location, attach.store_fname, bin_size)
else:
result[attach.id] = attach.db_datas
if bin_size:
result[attach.id] = int(result[attach.id])
return result
def _data_set(self, cr, uid, id, name, value, arg, context=None):