Skip to content

Commit

Permalink
[IMP] project_task_pull_request_state: code IMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodiay616 committed Nov 7, 2023
1 parent b4abf4e commit 1192515
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 27 deletions.
8 changes: 2 additions & 6 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:bb9eb5ec6fa57cb44e4351905de08de7e3cbd046be8d85c8cf8bc23408a88ae9
!! source digest: sha256:442d3934d77362069fd54a14bd95ff9bcac02734e36668a67ad8476c21f2a019
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -72,7 +72,6 @@ Contributors
------------

- Cetmix https://cetmix.com/
- Vladimir Kalmykov [email protected]

Maintainers
-----------
Expand All @@ -87,9 +86,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-isserver1| image:: https://github.com/isserver1.png?size=40px
:target: https://github.com/isserver1
:alt: isserver1
.. |maintainer-CetmixGitDrone| image:: https://github.com/CetmixGitDrone.png?size=40px
:target: https://github.com/CetmixGitDrone
:alt: CetmixGitDrone
Expand All @@ -99,7 +95,7 @@ promote its widespread use.

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-isserver1| |maintainer-CetmixGitDrone| |maintainer-Volodiay622|
|maintainer-CetmixGitDrone| |maintainer-Volodiay622|

This module is part of the `OCA/project <https://github.com/OCA/project/tree/16.0/project_task_pull_request_state>`_ project on GitHub.

Expand Down
2 changes: 1 addition & 1 deletion project_task_pull_request_state/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"category": "Project Management",
"website": "https://github.com/OCA/project",
"author": "Cetmix, Odoo Community Association (OCA)",
"maintainers": ["isserver1", "CetmixGitDrone", "Volodiay622"],
"maintainers": ["CetmixGitDrone", "Volodiay622"],
"license": "AGPL-3",
"application": False,
"installable": True,
Expand Down
31 changes: 15 additions & 16 deletions project_task_pull_request_state/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def _selection_pr_state(self):
("closed", "Closed"),
]

@api.model
def create(self, vals):
new_rec = super(ProjectTaskState, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
new_recs = super(ProjectTaskState, self).create(vals_list)

# Set pr state if URI is provided at creation
if "pr_uri" in vals:
new_rec._set_pr_state(vals.get("pr_uri"))
return new_rec
for new_rec, vals in zip(new_recs, vals_list):
if "pr_uri" in vals:
new_rec._set_pr_state(vals.get("pr_uri"))
return new_recs

def write(self, vals):
if "pr_uri" in vals:
Expand All @@ -41,18 +42,16 @@ def write(self, vals):
@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:
if not task.pr_uri:
task.pr_state = False
elif task.project_id and task.project_id.pr_state_default:
task.pr_state = task.project_id.pr_state_default
else:
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
ICPSudo = self.env["ir.config_parameter"].sudo()
pr_state_default = ICPSudo.get_param(
"project_task_pull_request_state.pr_state_default"
)
task.pr_state = pr_state_default or False

def _set_pr_state(self, pr_uri, pr_state=None):
"""Set PR state based on pr_uri
Expand Down
1 change: 0 additions & 1 deletion project_task_pull_request_state/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Cetmix <https://cetmix.com/>
- Vladimir Kalmykov <[email protected]>
5 changes: 2 additions & 3 deletions project_task_pull_request_state/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Project Task Pull Request State</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bb9eb5ec6fa57cb44e4351905de08de7e3cbd046be8d85c8cf8bc23408a88ae9
!! source digest: sha256:442d3934d77362069fd54a14bd95ff9bcac02734e36668a67ad8476c21f2a019
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/project/tree/16.0/project_task_pull_request_state"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/project-16-0/project-16-0-project_task_pull_request_state"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/project&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends functionality of the <strong>project_task_pull_request</strong>
Expand Down Expand Up @@ -419,7 +419,6 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Cetmix <a class="reference external" href="https://cetmix.com/">https://cetmix.com/</a></li>
<li>Vladimir Kalmykov <a class="reference external" href="mailto:volodiay616&#64;gmail.com">volodiay616&#64;gmail.com</a></li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -430,7 +429,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/isserver1"><img alt="isserver1" src="https://github.com/isserver1.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/CetmixGitDrone"><img alt="CetmixGitDrone" src="https://github.com/CetmixGitDrone.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/Volodiay622"><img alt="Volodiay622" src="https://github.com/Volodiay622.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/CetmixGitDrone"><img alt="CetmixGitDrone" src="https://github.com/CetmixGitDrone.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/Volodiay622"><img alt="Volodiay622" src="https://github.com/Volodiay622.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/16.0/project_task_pull_request_state">OCA/project</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,55 @@ def test_create_task_with_uri(self):
)
self.assertEqual(task_with_uri.pr_state, "open", "PR state must be 'open'")

def test_multi_create(self):
"""Create several tasks at the one time"""
pr_state_default_config = self.env["res.config.settings"].get_values()
self.assertNotIn("pr_state_default", pr_state_default_config)
self.ICPSudo.set_param(
"project_task_pull_request_state.pr_state_default", "closed"
)
pr_state_default_config = self.env["res.config.settings"].get_values()
self.assertEqual(
pr_state_default_config["pr_state_default"],
"closed",
"PR state must be 'closed'",
)
test_tasks_data = [
{
"name": "Test Task 1",
"project_id": self.project_1.id,
"pr_uri": "https://@my.pr.uri/pr",
},
{
"name": "Test Task 2",
"project_id": self.project_2.id,
"pr_uri": "https://@my.pr.uri/pr",
},
{
"name": "Test Task 3",
"project_id": self.project_3.id,
"pr_uri": "https://@my.pr.uri/pr",
},
]
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")
# Set empty values
self.env["res.config.settings"].set_values()
self.assertFalse(test_tasks[2].pr_state, "PR state must be False")

def test_set_pr_state(self):
"""Test _set_pr_state function"""
self.task_3.write({"pr_uri": "https://@my.pr.uri/pr"})
self.assertFalse(self.task_3.pr_state, "PR state must be False")
# Set system wide default PR state
self.ICPSudo.set_param(
"project_task_pull_request_state.pr_state_default", "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.task_1.write({"pr_uri": "https://@my.pr.uri/pr"})
self.assertEqual(self.task_1.pr_state, "draft", "PR state must be 'draft")
Expand Down

0 comments on commit 1192515

Please sign in to comment.