I want to remove the condition that generates the UserError in unlink method of 'res.partner' model:
def unlink(self):
running_sessions = self.env['pos.session'].sudo().search([('state', '!=', 'closed')])
if running_sessions:
raise UserError(
_("You cannot delete contacts while there are active PoS sessions. Close the session(s) %s first.")
% ", ".join(session.name for session in running_sessions)
)
return super(ResPartner, self).unlink()
I try by this code , but it always execute the standard function :
class ResPartner(models.Model):
_inherit = 'res.partner'
def unlink(self):
running_sessions = self.env['pos.session'].sudo().search(
[('state', 'not in', ['opening_control', 'opened', 'closing_control', 'closed'])])
if running_sessions:
raise UserError(
_("You cannot delete contacts while there are active PoS sessions. Close the session(s) %s first.")
% ", ".join(session.name for session in running_sessions)
)
else:
return ResPartner.unlink(self)
How can I do it ? Any help please?