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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
2
Replies
3641
Views
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
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
Actually i need to change the state ('processed') in the if condition to 'running.'