From fa7fa02aa0c791fad90b5aabccac29fbf1573038 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Fri, 30 May 2025 16:43:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soong_workflow/models/soong_workflow_node.py | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/soong_workflow/models/soong_workflow_node.py b/soong_workflow/models/soong_workflow_node.py index 94682e15b..e7b53dab5 100644 --- a/soong_workflow/models/soong_workflow_node.py +++ b/soong_workflow/models/soong_workflow_node.py @@ -408,14 +408,22 @@ class SoongWorkflowNodeButton(models.Model): @api.onchange('is_automatic', 'is_logged_by', 'is_by_company', 'is_by_group') def _onchange_boolean_fields(self): - """确保每次只有一个布尔字段为True""" - # 获取触发onchange的字段名 - triggered_field = self._context.get('last_changed_field') - # 如果有字段被触发且设为True,则将其他字段设为False - if triggered_field and getattr(self, triggered_field): - for field in ['is_automatic', 'is_logged_by', 'is_by_company', 'is_by_group']: - if field != triggered_field: - setattr(self, field, False) + checked_count = sum([ + self.is_automatic, + self.is_logged_by, + self.is_by_company, + self.is_by_group + ]) + + if checked_count > 1: + # 弹出警告并清空所有勾选(可选) + self.is_automatic = self.is_logged_by = self.is_by_company = self.is_by_group = False + return { + 'warning': { + 'title': '警告', + 'message': '只能勾选一个匹配方式!', + } + } @api.onchange('users_role_id', 'users_role_group_ids') def _onchange_role_selection(self):