Fix calls on multi instead of record

This commit is contained in:
Guewen Baconnier
2017-04-26 15:58:39 +02:00
parent fa008a3e83
commit 5d6fc2722c
@@ -17,18 +17,18 @@ class ShippingLabel(models.Model):
@api.depends('store_fname', 'db_datas') @api.depends('store_fname', 'db_datas')
def _compute_datas(self): def _compute_datas(self):
values = self.attachment_id._data_get('datas', None) for label in self:
for attach in self: values = label.attachment_id._data_get('datas', None)
attach.datas = values.get(attach.id) label.datas = values.get(label.id)
def _inverse_datas(self): def _inverse_datas(self):
# override in order to store files that need fast access, # override in order to store files that need fast access,
# we keep them in the database instead of the object storage # we keep them in the database instead of the object storage
location = self.attachment_id._storage() for label in self:
for attach in self: location = label.attachment_id._storage()
if location == 's3' and self.attachment_id._store_in_db_when_s3(): if location == 's3' and self.attachment_id._store_in_db_when_s3():
# compute the fields that depend on datas # compute the fields that depend on datas
value = attach.datas value = label.datas
bin_data = value and value.decode('base64') or '' bin_data = value and value.decode('base64') or ''
vals = { vals = {
'file_size': len(bin_data), 'file_size': len(bin_data),
@@ -38,11 +38,11 @@ class ShippingLabel(models.Model):
'index_content': False, 'index_content': False,
'store_fname': False, 'store_fname': False,
} }
fname = attach.store_fname fname = label.store_fname
# write as superuser, as user probably does not # write as superuser, as user probably does not
# have write access # have write access
super(ShippingLabel, attach.sudo()).write(vals) super(ShippingLabel, label.sudo()).write(vals)
if fname: if fname:
self.attachment_id._file_delete(fname) self.attachment_id._file_delete(fname)
continue continue
self.attachment_id._data_set('datas', attach.datas, None) self.attachment_id._data_set('datas', label.datas, None)