summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-10-13 12:01:34 +0000
committerRaphael Collet <rco@odoo.com>2020-10-13 17:05:20 +0000
commit3563738ca5dd97791d5f32d8ffc40d07a8a95386 (patch)
tree29b5497f7266a422da289bad8edd426a264a9735
parent9b71458937fd15f357923434b41f95eb95af57a1 (diff)
[FIX] core: assignment of binary field on new record with origin
The assignment of a binary field on a new record with origin did actually modify the attachment storing the value of the field on the origin record! The fix is simply to avoid messing up with attachments when updating new records. closes odoo/odoo#59918 X-original-commit: 6778c4c10fa68c46bde6fae176f547f905e9c02f Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py4
-rw-r--r--odoo/fields.py7
2 files changed, 8 insertions, 3 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py
index 441362e7038..f93baf0e83e 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1965,6 +1965,10 @@ class TestFields(TransactionCaseWithUserDemo):
self.assertEqual(record.image, image_h)
self.assertEqual(new_record.image, image_h)
+ # assignment to new record with origin should not do any query
+ with self.assertQueryCount(0):
+ new_record.image = image_w
+
def test_95_binary_bin_size(self):
binary_value = base64.b64encode(b'content')
binary_size = b'7.00 bytes'
diff --git a/odoo/fields.py b/odoo/fields.py
index 324450bf80e..99d2ac9c8e4 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -2049,20 +2049,21 @@ class Binary(Field):
cache.update(records, self, [cache_value] * len(records))
# retrieve the attachments that store the values, and adapt them
- if self.store:
+ if self.store and any(records._ids):
+ real_records = records.filtered('id')
atts = records.env['ir.attachment'].sudo()
if not_null:
atts = atts.search([
('res_model', '=', self.model_name),
('res_field', '=', self.name),
- ('res_id', 'in', records.ids),
+ ('res_id', 'in', real_records.ids),
])
if value:
# update the existing attachments
atts.write({'datas': value})
atts_records = records.browse(atts.mapped('res_id'))
# create the missing attachments
- missing = (records - atts_records).filtered('id')
+ missing = (real_records - atts_records)
if missing:
atts.create([{
'name': self.name,