Skip to content

Commit

Permalink
[IMP] project_task_pull_request_state:after review
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Volodiay616 committed Jan 22, 2024
1 parent 3616588 commit d195054
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
11 changes: 6 additions & 5 deletions project_task_pull_request_state/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project Task Pull Request State
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:acd2039cd12805d8338b8489c2a4826a6997cd805e91aa6f03d2bd5960f0d88a
!! source digest: sha256:e4361ed521f7d798fd58d0076a5554ecb61e5a99e05a6720cce230670b2bd6cf
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -32,7 +32,7 @@ This module extends functionality of the project_task_pull_request module. It ad
"State" field to Task alongside with PR URI field.

Following pre-defined states are available: "Draft", "Open", "Merged", "Closed". You can
add or modify this list easily by overriding the "\_selection_pr_state" function in the
add or modify this list easily by overriding the "selection_pr_state" function in the
"project.task" model

**Table of contents**
Expand Down Expand Up @@ -79,9 +79,10 @@ Authors
Contributors
~~~~~~~~~~~~

* Cetmix <https://cetmix.com/>
Ivan Sokolov
Vladimir Kalmykov
* `Cetmix <https://cetmix.com/>`__

* Ivan Sokolov
* Vladimir Kalmykov

Maintainers
~~~~~~~~~~~
Expand Down
2 changes: 0 additions & 2 deletions project_task_pull_request_state/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Copyright Cetmix OU 2023
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0).
from . import project_task
from . import project_project
from . import res_config_settings
4 changes: 2 additions & 2 deletions project_task_pull_request_state/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from odoo import fields, models


class ProjectState(models.Model):
class Project(models.Model):
_inherit = "project.project"

pr_state_default = fields.Selection(
selection=lambda self: self.env["project.task"]._selection_pr_state(),
selection=lambda self: self.env["project.task"].selection_pr_state(),
string="Default PR State",
help="Default PR state that will be set when PR URI "
"is added to a task in this project",
Expand Down
6 changes: 3 additions & 3 deletions project_task_pull_request_state/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from odoo import api, fields, models


class ProjectTaskState(models.Model):
class ProjectTask(models.Model):
_inherit = "project.task"

pr_state = fields.Selection(
selection=lambda self: self._selection_pr_state(),
selection=lambda self: self.selection_pr_state(),
tracking=True,
copy=False,
string="PR State",
Expand All @@ -17,7 +17,7 @@ class ProjectTaskState(models.Model):
readonly=False,
)

def _selection_pr_state(self):
def selection_pr_state(self):
"""Function to select the state of the pull request"""
return [
("open", "Open"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pr_state_default = fields.Selection(
selection=lambda self: self.env["project.task"]._selection_pr_state(),
selection=lambda self: self.env["project.task"].selection_pr_state(),
string="Default PR State",
config_parameter="project_task_pull_request_state.pr_state_default",
help="Default PR state that will be set when "
Expand Down
7 changes: 4 additions & 3 deletions project_task_pull_request_state/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Cetmix <https://cetmix.com/>
Ivan Sokolov
Vladimir Kalmykov
* `Cetmix <https://cetmix.com/>`__

* Ivan Sokolov
* Vladimir Kalmykov
2 changes: 1 addition & 1 deletion project_task_pull_request_state/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ This module extends functionality of the project_task_pull_request module. It ad
"State" field to Task alongside with PR URI field.

Following pre-defined states are available: "Draft", "Open", "Merged", "Closed". You can
add or modify this list easily by overriding the "\_selection_pr_state" function in the
add or modify this list easily by overriding the "selection_pr_state" function in the
"project.task" model
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ def test_pull_request_state_set_default(self):
tasks = self.Task.browse([self.task_1.id, self.task_2.id, self.task_3.id])
tasks.write({"pr_uri": "https://@my.pr.uri/pr"})

self.assertEqual(self.task_1.pr_state, "draft", "PR state must be 'draft")
self.assertEqual(self.task_2.pr_state, "open", "PR state must be 'open")
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(self.task_1.pr_state, "draft", "PR state must be 'draft'")
self.assertEqual(self.task_2.pr_state, "open", "PR state must be 'open'")
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed'")

# Change pr_state
tasks.write({"pr_state": "closed"})

self.assertEqual(self.task_1.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(self.task_2.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(self.task_1.pr_state, "closed", "PR state must be 'closed'")
self.assertEqual(self.task_2.pr_state, "closed", "PR state must be 'closed'")
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed'")

def test_pull_request_state_set_explicit(self):
"""Set PR state from vals when PR URI is added to task"""
# Set to several existing tasks at once
tasks = self.Task.browse([self.task_1.id, self.task_2.id, self.task_3.id])
tasks.write({"pr_uri": "https://@my.pr.uri/pr", "pr_state": "merged"})

self.assertEqual(self.task_1.pr_state, "merged", "PR state must be 'merged")
self.assertEqual(self.task_2.pr_state, "merged", "PR state must be 'merged")
self.assertEqual(self.task_3.pr_state, "merged", "PR state must be 'merged")
self.assertEqual(self.task_1.pr_state, "merged", "PR state must be 'merged'")
self.assertEqual(self.task_2.pr_state, "merged", "PR state must be 'merged'")
self.assertEqual(self.task_3.pr_state, "merged", "PR state must be 'merged'")

def test_create_task_with_uri(self):
"""Add PR URI when task created"""
Expand Down Expand Up @@ -130,9 +130,9 @@ def test_multi_create(self):
]
test_tasks = self.Task.create(test_tasks_data)

self.assertEqual(test_tasks[0].pr_state, "draft", "PR state must be 'draft")
self.assertEqual(test_tasks[1].pr_state, "open", "PR state must be 'open")
self.assertEqual(test_tasks[2].pr_state, "closed", "PR state must be 'closed")
self.assertEqual(test_tasks[0].pr_state, "draft", "PR state must be 'draft'")
self.assertEqual(test_tasks[1].pr_state, "open", "PR state must be 'open'")
self.assertEqual(test_tasks[2].pr_state, "closed", "PR state must be 'closed'")

def test_set_pr_state(self):
"""Test _set_pr_state function"""
Expand All @@ -142,10 +142,10 @@ def test_set_pr_state(self):
self._set_default_pr_state("closed")

self.task_3.write({"pr_uri": "https://@my.pr.uri/new_pr"})
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(self.task_3.pr_state, "closed", "PR state must be 'closed'")

self.task_1.write({"pr_uri": "https://@my.pr.uri/pr"})
self.assertEqual(self.task_1.pr_state, "draft", "PR state must be 'draft")
self.assertEqual(self.task_1.pr_state, "draft", "PR state must be 'draft'")
# Remove PR URI
self.task_1.write({"pr_uri": ""})
self.assertFalse(self.task_1.pr_state, "PR state must be False")
Expand All @@ -158,7 +158,7 @@ def test_set_pr_state(self):
"pr_uri": "https://@my.pr.uri/pr",
}
)
self.assertEqual(test_task.pr_state, "closed", "PR state must be 'closed")
self.assertEqual(test_task.pr_state, "closed", "PR state must be 'closed'")

def test_set_pr_state_default(self):
"""Set values for the pr_state_default parameter"""
Expand Down

0 comments on commit d195054

Please sign in to comment.