Community: Framework mailing list archives

expert-framework@mail.odoo.com

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

by
Pedro M. Baeza
- 10/16/2014 13:16:39
Or you can set self.datas = False at the beginning and it can be overwritten if all conditions are met...

Regards.

2014-10-16 15:27 GMT+02:00 Maxim Litnitskiy <litnimaxster@gmail.com>:
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)

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe