Skip to content

Commit

Permalink
[IMP] project_task_pull_request_state: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodiay616 committed Nov 6, 2023
1 parent d463886 commit 21886e2
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions project_task_pull_request_state/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 21886e2

Please sign in to comment.