Skip to Content
Menu
This question has been flagged
2 Replies
4111 Views

Hi,
I have a module which super the unlink function of my model with some condition. I need to rewrite this method with some new conditions.

Eg: 
 class MechancalDetails(models.Model):
     _inherit = 'mechanical.operation'                                                         
     def unlink(self):
           if any(opr.state == 'processed' for opr in self):
                 raise UserError(_('You cannot delete a processing operation.'))
           return super(MechancalDetails, self).unlink()

I need to rewrite this function and change the if condition.

Avatar
Discard
Best Answer

Hi,

First import the class of the override unlink method and rewrite the code and make the changes you need.

Eg:

from odoo.addons.existing_module.models.file import MechancalDetails


class MechanicalDetailsInherit(models.Model):
_inherit = 'mechanical.operation'

def unlink(self):
# Your condition
return super(MechancalDetails, self).unlink()

Hope it helps

Avatar
Discard
Best Answer

Hi,

You can try this,

class MechancalDetails(models.Model):
_inherit = 'mechanical.operation'

def unlink(self):
if any(opr.state == 'processed' for opr in self):
raise UserError(_('You cannot delete a processing operation.'))
# make changes needed
return models.Model.unlink(self)

before returning you can make necessary changes in the if statement.

See the similar case done with the default_get function:  Bypass inherited function default_get()

Thanks

Avatar
Discard
Author

Actually i need to change the state ('processed') in the if condition to 'running.'

Related Posts Replies Views Activity
1
Jul 19
2046
2
Oct 15
9554
1
Mar 15
9796
1
Sep 24
3446
3
May 21
7758