Chamal Chamal - 1 month ago 21
Python Question

how to display openerp error message

In my student module I inherited res.partner. And I want to restrict to modify name in partner view if partner is a student. here is my cord.

from openerp.osv import osv, fields


class res_partner(osv.Model):
_inherit = 'res.partner'
_columns = {
'name': fields.char('Name', size=250, required=True, select=True),
'is_student': fields.boolean('Student', readonly=True),
}

def write(self, cr, uid, ids, vals, context=None):

stud = self.browse(cr, uid, ids, context=context)[0]

if ('name' in vals) & (stud.is_student is True):
raise "Cannot Edit"
else:
return super(res_partner, self).write(cr, uid, ids, vals, context=context)


it is working but I want to display error message in a message box. not a exception. How could I do this?

Answer
raise osv.except_osv(('Error'), ('Error  Cannot Edit'))