Community: Framework mailing list archives

expert-framework@mail.odoo.com

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

by
Maxim Litnitskiy
- 10/16/2014 09:25:46
Sorry for spamming :-)
Also I have to set self.datas = False on IOError when cannot read file otherwise Field is accessed before being computed is raised.
Here is it:

    @api.one
    def get_full_path(self):
        sound_dir = os.path.join(tools.config.filestore(self.env.cr.dbname), 'sounds')
        filename = os.path.join(sound_dir, self.datas_fname)
        return filename

    
    @api.one
    def _data_get(self):
        if not  self.datas_fname:
            self.datas = False
            return            
        filename = self.get_full_path()[0]
        try:
            r = open(filename, 'rb').read().encode('base64')
            self.datas = r
        except IOError:
            self.datas = False
            _logger.exception('_data_get reading: %s' % filename)