At first I have a module A overwrite method write and add a constrains likes this:
@api.multi
def write(self, vals):
if 'employee_id' in vals:
if not self.env['hr.employee'].browse(vals['employee_id']).user_id:
raise UserError(_('You must link this employee to a user'))
return super(class_name, self).write(vals)
Then I create a module B inherit module A and I want to remove the constraints in write method but no way. I've tried to inherit write method and remove the constrains but no luck, all I can do is replacing constrains string by another sentences but it 's not what I want, how can I resolve it ?
Update #1: based on suggestion of @thangtn but it still not working
@api.multi
def write(self, vals):
try:
if 'employee_id' in vals:
if not self.env['hr.employee'].browse(vals['employee_id']).user_id:
raise UserError(_('You must link this employee to a user'))
except UserError
pass
super(class_name, self).write(vals)
Update #2: problem is resolved by change super(class_name, self).write(vals)
to models.Model.write(self, vals)
in above code (Update #1)