diff --git a/project_task_pull_request_state/models/project_task.py b/project_task_pull_request_state/models/project_task.py index ff6ded64ab..6207cef697 100644 --- a/project_task_pull_request_state/models/project_task.py +++ b/project_task_pull_request_state/models/project_task.py @@ -11,6 +11,8 @@ class ProjectTaskState(models.Model): track_visibility="onchange", copy=False, string="PR State", + compute="_compute_pr_state", + readonly=False, ) def _selection_pr_state(self): @@ -36,20 +38,21 @@ def write(self, vals): self._set_pr_state(vals.get("pr_uri"), vals.get("pr_state")) return super(ProjectTaskState, self).write(vals) - @api.onchange("pr_uri") - def onchange_pr_uri(self): - """Ser PR state when PR URI is entered in form""" - if self.pr_uri and not self.pr_state: - if self.project_id and self.project_id.pr_state_default: - self.pr_state = self.project_id.pr_state_default + @api.depends("pr_uri", "project_id.pr_state_default") + def _compute_pr_state(self): + for task in self: + pr_uri = task.pr_uri + if not pr_uri: + task.pr_state = False else: - ICPSudo = self.env["ir.config_parameter"].sudo() - pr_state = ICPSudo.get_param( - "project_task_pull_request_state.pr_state_default" - ) - self.pr_state = pr_state - if not self.pr_uri: - self.pr_state = False + if task.project_id and task.project_id.pr_state_default: + task.pr_state = task.project_id.pr_state_default + else: + ICPSudo = self.env["ir.config_parameter"].sudo() + pr_state = ICPSudo.get_param( + "project_task_pull_request_state.pr_state_default" + ) + task.pr_state = pr_state def _set_pr_state(self, pr_uri, pr_state=None): """Set PR state based on pr_uri