Community: Framework mailing list archives

Re: v8.0 - Cannot create computed field - Field is accessed before being computed.

Maxim Litnitskiy
- 10/16/2014 06:46:44
Hi Axel.
Thanks for your reply.
But I already do it.
Please look at this code.
This works on read and update (when I manually create a record in database), I can download file and I can change it.
And only gives error when I try to create a new record via Create button.

import logging
from openerp import fields, models, api, _

_logger = logging.getLogger(__name__)

class SoundFile(models.Model):
    _name = 'asterisk_dialer.sound_file'
    name = fields.Char(string=_('Sound file name'), required=True)
    datas = fields.Binary(compute='_data_get', inverse='_data_set', string=_('File content'), required=True)
    datas_fname = fields.Char(string=_('File name'), required=True)
    description = fields.Text(string=_('Description'))
    def _data_get(self):
        if not  self.datas_fname:
        filename = '/tmp/%s' % self.datas_fname
            r = open(filename, 'rb').read().encode('base64')
            self.datas = r
        except IOError:
            _logger.exception('_data_get reading: %s' % filename)

    def _data_set(self):        
        filename = '/tmp/%s' % self.datas_fname
            with open(filename, 'wb') as fp:
                bin_value = self.datas.decode('base64')
        except IOError:
            _logger.exception('_data_set writing: %s' % filename)