Skip to content

Commit 910e853

Browse files
committed
fix(spp_api_v2): protect system_id from manual edit and deletion
1 parent ca0c89b commit 910e853

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

spp_api_v2/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from . import ir_http_patch
1313
from . import res_partner_mobile
1414
from . import res_partner_system_id
15+
from . import spp_registry_id_system
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
2+
"""Protect system_id registry entries from manual edits."""
3+
4+
from odoo import _, api, models
5+
from odoo.exceptions import UserError
6+
7+
8+
class SPPRegistryIdSystem(models.Model):
9+
_inherit = "spp.registry.id"
10+
11+
@api.ondelete(at_uninstall=False)
12+
def _prevent_system_id_delete(self):
13+
"""Prevent deletion of system_id entries."""
14+
for rec in self:
15+
if rec.id_type_id and rec.id_type_id.code == "system_id":
16+
raise UserError(_("System ID is auto-generated and cannot be deleted."))
17+
18+
def write(self, vals):
19+
"""Prevent editing value of system_id entries."""
20+
if "value" in vals:
21+
for rec in self:
22+
if rec.id_type_id and rec.id_type_id.code == "system_id":
23+
raise UserError(_("System ID is auto-generated and cannot be modified."))
24+
return super().write(vals)

0 commit comments

Comments
 (0)