Skip to content

Commit f1a8517

Browse files
kg-ucsAbranes
authored andcommitted
[MIG] project_task_code: Migration to 16.0
1 parent 15b5891 commit f1a8517

File tree

12 files changed

+111
-24
lines changed

12 files changed

+111
-24
lines changed

project_task_code/README.rst

+14-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Sequential Code for Tasks
1414
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1515
:alt: License: AGPL-3
1616
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
17-
:target: https://github.com/OCA/project/tree/15.0/project_task_code
17+
:target: https://github.com/OCA/project/tree/16.0/project_task_code
1818
:alt: OCA/project
1919
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/project-15-0/project-15-0-project_task_code
20+
:target: https://translation.odoo-community.org/projects/project-16-0/project-16-0-project_task_code
2121
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/140/15.0
24-
:alt: Try me on Runbot
22+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
23+
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/project&target_branch=16.0
24+
:alt: Try me on Runboat
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
2727

@@ -41,6 +41,12 @@ To change the task code sequence, you must:
4141
#. Go to Settings > Technical > Sequences & Identifiers > Sequences.
4242
#. Click on "Task code" sequence to edit.
4343

44+
To activate the task code sequence unique constraint, you must:
45+
46+
#. Activate the developer mode.
47+
#. Go to Project > Configuration > Settings.
48+
#. Check the "Unique Task Code" check box and save.
49+
4450
Usage
4551
=====
4652

@@ -56,7 +62,7 @@ Bug Tracker
5662
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/issues>`_.
5763
In case of trouble, please check there if your issue has already been reported.
5864
If you spotted it first, help us smashing it by providing a detailed and welcomed
59-
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_task_code%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
65+
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_task_code%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
6066

6167
Do not contact contributors directly about support or help with technical issues.
6268

@@ -86,6 +92,7 @@ Contributors
8692
* Saran Lim. <[email protected]>
8793
* Tharathip Chaweewongphan <[email protected]>
8894
* Ruchir Shukla <[email protected]>
95+
* Abraham Anes <[email protected]>
8996

9097
Maintainers
9198
~~~~~~~~~~~
@@ -100,6 +107,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
100107
mission is to support the collaborative development of Odoo features and
101108
promote its widespread use.
102109

103-
This module is part of the `OCA/project <https://github.com/OCA/project/tree/15.0/project_task_code>`_ project on GitHub.
110+
This module is part of the `OCA/project <https://github.com/OCA/project/tree/16.0/project_task_code>`_ project on GitHub.
104111

105112
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

project_task_code/__manifest__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Sequential Code for Tasks",
6-
"version": "15.0.1.0.4",
6+
"version": "16.0.1.0.0",
77
"category": "Project Management",
88
"author": "OdooMRP team, "
99
"AvanzOSC, "
@@ -17,6 +17,7 @@
1717
"data": [
1818
"data/task_sequence.xml",
1919
"views/project_view.xml",
20+
"views/res_config_settings_view.xml",
2021
],
2122
"installable": True,
2223
"pre_init_hook": "pre_init_hook",

project_task_code/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
22

33
from . import project_task
4+
from . import res_config_settings

project_task_code/models/project_task.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
56

67

78
class ProjectTask(models.Model):
@@ -15,23 +16,29 @@ class ProjectTask(models.Model):
1516
copy=False,
1617
)
1718

18-
_sql_constraints = [
19-
("project_task_unique_code", "UNIQUE (code)", _("The code must be unique!")),
20-
]
19+
@api.constrains("code")
20+
def _check_project_task_unique_code(self):
21+
project_task_unique_code = (
22+
self.env["ir.config_parameter"]
23+
.sudo()
24+
.get_param("project_task_code.project_task_unique_code")
25+
)
26+
27+
if not project_task_unique_code:
28+
return
29+
30+
for task in self:
31+
if self.search([("code", "=", task.code), ("id", "!=", task.id)], limit=1):
32+
raise ValidationError(_("The code must be unique!"))
2133

2234
@api.model_create_multi
2335
def create(self, vals_list):
24-
new_list = []
2536
for vals in vals_list:
2637
if vals.get("code", "/") == "/":
27-
new_vals = dict(
28-
vals,
29-
code=self.env["ir.sequence"].next_by_code("project.task") or "/",
38+
vals["code"] = (
39+
self.env["ir.sequence"].next_by_code("project.task") or "/"
3040
)
31-
else:
32-
new_vals = vals
33-
new_list.append(new_vals)
34-
return super().create(new_list)
41+
return super().create(vals_list)
3542

3643
def name_get(self):
3744
result = super().name_get()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2023 Abraham Anes <[email protected]>
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
project_task_unique_code = fields.Boolean(
11+
string="Unique Task Code",
12+
config_parameter="project_task_code.project_task_unique_code",
13+
default=False,
14+
)

project_task_code/readme/CONFIGURE.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ To change the task code sequence, you must:
33
#. Activate the developer mode.
44
#. Go to Settings > Technical > Sequences & Identifiers > Sequences.
55
#. Click on "Task code" sequence to edit.
6+
7+
To activate the task code sequence unique constraint, you must:
8+
9+
#. Activate the developer mode.
10+
#. Go to Project > Configuration > Settings.
11+
#. Check the "Unique Task Code" check box and save.

project_task_code/readme/CONTRIBUTORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
* Saran Lim. <[email protected]>
1212
* Tharathip Chaweewongphan <[email protected]>
1313
* Ruchir Shukla <[email protected]>
14+
* Abraham Anes <[email protected]>

project_task_code/static/description/index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Sequential Code for Tasks</title>
88
<style type="text/css">
99

@@ -367,7 +367,7 @@ <h1 class="title">Sequential Code for Tasks</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" 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" 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" href="https://github.com/OCA/project/tree/15.0/project_task_code"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-15-0/project-15-0-project_task_code"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/140/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
370+
<p><a class="reference external" 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" 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" href="https://github.com/OCA/project/tree/16.0/project_task_code"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-16-0/project-16-0-project_task_code"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?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>
371371
<p>This module adds a sequential code for tasks.</p>
372372
<p><strong>Table of contents</strong></p>
373373
<div class="contents local topic" id="contents">
@@ -391,6 +391,12 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
391391
<li>Go to Settings &gt; Technical &gt; Sequences &amp; Identifiers &gt; Sequences.</li>
392392
<li>Click on “Task code” sequence to edit.</li>
393393
</ol>
394+
<p>To activate the task code sequence unique constraint, you must:</p>
395+
<ol class="arabic simple">
396+
<li>Activate the developer mode.</li>
397+
<li>Go to Project &gt; Configuration &gt; Settings.</li>
398+
<li>Check the “Unique Task Code” check box and save.</li>
399+
</ol>
394400
</div>
395401
<div class="section" id="usage">
396402
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
@@ -404,7 +410,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
404410
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/project/issues">GitHub Issues</a>.
405411
In case of trouble, please check there if your issue has already been reported.
406412
If you spotted it first, help us smashing it by providing a detailed and welcomed
407-
<a class="reference external" href="https://github.com/OCA/project/issues/new?body=module:%20project_task_code%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
413+
<a class="reference external" href="https://github.com/OCA/project/issues/new?body=module:%20project_task_code%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
408414
<p>Do not contact contributors directly about support or help with technical issues.</p>
409415
</div>
410416
<div class="section" id="credits">
@@ -433,6 +439,7 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
433439
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
434440
<li>Tharathip Chaweewongphan &lt;<a class="reference external" href="mailto:tharathipc&#64;ecosoft.co.th">tharathipc&#64;ecosoft.co.th</a>&gt;</li>
435441
<li>Ruchir Shukla &lt;<a class="reference external" href="mailto:ruchir&#64;bizzappdev.com">ruchir&#64;bizzappdev.com</a>&gt;</li>
442+
<li>Abraham Anes &lt;<a class="reference external" href="mailto:abrahamanes&#64;gmail.com">abrahamanes&#64;gmail.com</a>&gt;</li>
436443
</ul>
437444
</div>
438445
<div class="section" id="maintainers">
@@ -442,7 +449,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
442449
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
443450
mission is to support the collaborative development of Odoo features and
444451
promote its widespread use.</p>
445-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/15.0/project_task_code">OCA/project</a> project on GitHub.</p>
452+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/16.0/project_task_code">OCA/project</a> project on GitHub.</p>
446453
<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>
447454
</div>
448455
</div>

project_task_code/tests/test_project_task_code.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
import odoo.tests.common as common
5+
from odoo.exceptions import ValidationError
56

67

78
class TestProjectTaskCode(common.TransactionCase):
@@ -10,7 +11,7 @@ def setUp(self):
1011
self.project_task_model = self.env["project.task"]
1112
self.ir_sequence_model = self.env["ir.sequence"]
1213
self.task_sequence = self.env.ref("project_task_code.sequence_task")
13-
self.project_task = self.env.ref("project.project_task_1")
14+
self.project_task = self.env.ref("project.project_1_task_1")
1415

1516
def test_old_task_code_assign(self):
1617
project_tasks = self.project_task_model.search([])
@@ -38,3 +39,15 @@ def test_name_get(self):
3839
)
3940
result = project_task.name_get()
4041
self.assertEqual(result[0][1], "[%s] Task Testing Get Name" % code)
42+
43+
def test_unique_task_code(self):
44+
# Enable unique task code constraint
45+
self.env["ir.config_parameter"].sudo().set_param(
46+
"project_task_code.project_task_unique_code", True
47+
)
48+
49+
project_task = self.project_task_model.create({"name": "Testing task code"})
50+
with self.assertRaises(ValidationError):
51+
self.project_task_model.create(
52+
{"name": "Testing task code", "code": project_task.code}
53+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<record id="res_config_settings_view_form_inherit" model="ir.ui.view">
4+
<field name="name">res.config.settings.view.form.inherit</field>
5+
<field name="model">res.config.settings</field>
6+
<field name="inherit_id" ref="project.res_config_settings_view_form" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//div[@id='tasks_management']" position="inside">
9+
<div class="col-12 col-lg-6 o_setting_box" id="project_task_code">
10+
<div class="o_setting_left_pane">
11+
<field name="project_task_unique_code" />
12+
</div>
13+
<div class="o_setting_right_pane">
14+
<label for="project_task_unique_code" />
15+
<div class="text-muted">
16+
Makes the task code have to be unique
17+
</div>
18+
</div>
19+
</div>
20+
</xpath>
21+
</field>
22+
</record>
23+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../project_task_code

setup/project_task_code/setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)