I have added a Boolean attribute to res_config_settings. When the Boolean is False I want to delete all records in a custom Model ('my.device').
I have tried three different approaches:
1.In res_config_settings
:
devices = self.env['my.device'].browse()
devices.unlink()
res_config_settings
:devices = self.env['my.device'].browse()
for d in devices:
d.unlink()
my.device
modeldef unlink_all(self):
for rec in self:
rec.unlink()
Then call self.env['pushbullet.device'].unlink_all()
from res_config_settings
.
None of the options work but strangely, the first time I tried Option 1, all but one record was deleted.
Depends on two special factors: security and active mechanism. To really delete everything use sudo()
to act as superuser and .with_context(active_test=False)
to also find inactive records.
Example:
self.env['my.device'].sudo().with_context(active_test=False).search([]).unlink()
Or maybe more readable:
device_sudo = self.env['my.device'].sudo()
all_devices = device_sudo.with_context(active_test=False).search([])
all_devices.unlink()
If you don't want to bypass security/access rules, just remove the sudo
parts.