O'Reilly logo

Odoo Development Cookbook by Daniel Reis, Alexandre Fayolle, Holger Brunn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reporting errors to the user

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 which writes a file to disk encounters an error.

Getting ready

To use this recipe, you need a method, which can have an abnormal condition. We will use the following one:

import os
from openerp import models, fields, api

class SomeModel(models.Model):
    data = fields.Text('Data')

    @api.multi
    def save(self, filename):
        path = os.path.join('/opt/exports', filename)
        with open(path, 'w') as fobj:
            for record in self:
                fobj.write(record.data)
                fobj.write('\n')

This method can fail because of permission issues, or a full ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required