During method execution, it is sometimes necessary to abort the processing because an error condition was met. This recipe shows how to do this so that a helpful error message is displayed to the user when a method that writes a file to disk encounters an error.
Reporting errors to the user
Getting ready
To use this recipe, you need a method with an error condition. We will use the following one:
import os from odoo import models, fields, api class SomeModel(models.Model):
_name = 'some.model' data = fields.Text('Data') @api.multi def save(self, filename): path = os.path.join('/opt/exports', filename) with open(path, 'w') as fobj: ...