Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
disable selecting self in parent, disable creation of field, improve …
Browse files Browse the repository at this point in the history
…constrains
  • Loading branch information
reichie020212 committed Jan 4, 2024
1 parent 6514df8 commit 5ef43e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions spp_audit_post/models/spp_audit_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions spp_audit_post/views/spp_audit_rule_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="field_id_domain" invisible="1" />
<field name="parent_id" options="{'no_create': True, 'no_open': True}" />
<field name="parent_id" options="{'no_create': True, 'no_open': True, 'no_edit': True}" />
</xpath>

<xpath expr="//field[@name='log_unlink']" position="after">
<field
name="field_id"
attrs="{'invisible': [('parent_id', '=', False)]}"
options="{'no_open': True}"
options="{'no_open': True, 'no_create': True, 'no_edit': True}"
domain="field_id_domain"
/>
</xpath>
Expand Down

0 comments on commit 5ef43e0

Please sign in to comment.