summaryrefslogtreecommitdiff
path: root/odoo/fields.py
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 /odoo/fields.py
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>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py7
1 files changed, 4 insertions, 3 deletions
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,