[FIX] fields: 'bin_size' must have no effect on arbitrary binary field values
This fixes a regression introduced by 291a0e99d137142bd24addd1054c1357ddd7125a. closes odoo/odoo#39178 X-original-commit: 852ee32e3419c210a3844b0f943af8dd2bbdae88 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -525,6 +525,13 @@ class ModelBinary(models.Model):
|
||||
binary = fields.Binary()
|
||||
binary_related_store = fields.Binary("Binary Related Store", related='binary', store=True, readonly=False)
|
||||
binary_related_no_store = fields.Binary("Binary Related No Store", related='binary', store=False, readonly=False)
|
||||
binary_computed = fields.Binary(compute='_compute_binary')
|
||||
|
||||
@api.depends('binary')
|
||||
def _compute_binary(self):
|
||||
# arbitrary value: 'bin_size' must have no effect
|
||||
for record in self:
|
||||
record.binary_computed = [(record.id, bool(record.binary))]
|
||||
|
||||
|
||||
class ModelImage(models.Model):
|
||||
|
||||
@@ -1598,6 +1598,18 @@ class TestFields(common.TransactionCase):
|
||||
assertBinaryValue(record_no_bin_size, binary_value)
|
||||
assertBinaryValue(record_bin_size, binary_size)
|
||||
|
||||
# check computed binary field with arbitrary Python value
|
||||
record = self.env['test_new_api.model_binary'].create({})
|
||||
record.flush()
|
||||
record.invalidate_cache()
|
||||
record_no_bin_size = record.with_context(bin_size=False)
|
||||
record_bin_size = record.with_context(bin_size=True)
|
||||
|
||||
expected_value = [(record.id, False)]
|
||||
self.assertEqual(record.binary_computed, expected_value)
|
||||
self.assertEqual(record_no_bin_size.binary_computed, expected_value)
|
||||
self.assertEqual(record_bin_size.binary_computed, expected_value)
|
||||
|
||||
|
||||
class TestX2many(common.TransactionCase):
|
||||
def test_definition_many2many(self):
|
||||
|
||||
+2
-1
@@ -1921,7 +1921,8 @@ class Binary(Field):
|
||||
except (TypeError, binascii.Error):
|
||||
pass
|
||||
try:
|
||||
value = human_size(len(value))
|
||||
if isinstance(value, (bytes, _BINARY)):
|
||||
value = human_size(len(value))
|
||||
except (TypeError):
|
||||
pass
|
||||
cache_value = self.convert_to_cache(value, record)
|
||||
|
||||
Reference in New Issue
Block a user