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
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.'
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jul 19
|
2046 | ||
|
2
Oct 15
|
9554 | ||
|
1
Mar 15
|
9796 | ||
|
1
Sep 24
|
3446 | ||
|
3
May 21
|
7758 |