From 5ef43e0ba604677488bf3935dd42c0a0ebdf2caa Mon Sep 17 00:00:00 2001 From: red Date: Thu, 4 Jan 2024 15:32:02 +0800 Subject: [PATCH] disable selecting self in parent, disable creation of field, improve constrains --- spp_audit_post/models/spp_audit_rule.py | 14 +++++--------- spp_audit_post/views/spp_audit_rule_views.xml | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/spp_audit_post/models/spp_audit_rule.py b/spp_audit_post/models/spp_audit_rule.py index 75c1880e..0c3d2cb7 100644 --- a/spp_audit_post/models/spp_audit_rule.py +++ b/spp_audit_post/models/spp_audit_rule.py @@ -6,6 +6,8 @@ class SppAuditRule(models.Model): _inherit = "spp.audit.rule" + _parent_name = "parent_id" + _parent_store = True parent_id = fields.Many2one( "spp.audit.rule", @@ -29,6 +31,8 @@ class SppAuditRule(models.Model): readonly=True, ) + parent_path = fields.Char() + @api.onchange("model_id") def _onchange_model_id(self): super()._onchange_model_id() @@ -52,15 +56,7 @@ def _compute_field_id_domain(self): ] rec.field_id_domain = json.dumps(domain) - @api.constrains("field_id") - def _check_field_id(self): - for rec in self: - if rec.parent_id and not rec.field_id: - raise ValidationError( - _("Field is required if the rule is a child rule.") - ) - - @api.constrains("model_id", "field_id") + @api.constrains("parent_id", "field_id") def _check_model_id_field_id(self): for rec in self: if rec.parent_id and not rec.field_id: diff --git a/spp_audit_post/views/spp_audit_rule_views.xml b/spp_audit_post/views/spp_audit_rule_views.xml index 82b02044..a6907fa4 100644 --- a/spp_audit_post/views/spp_audit_rule_views.xml +++ b/spp_audit_post/views/spp_audit_rule_views.xml @@ -7,14 +7,14 @@ - +