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):