Chamal Chamal - 1 year ago 128
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"
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 Source
raise osv.except_osv(('Error'), ('Error  Cannot Edit'))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download