Skip to content

Commit facf66b

Browse files
committed
Revert "[IMP] project_task_code: parameter for unicity constraint"
This reverts commit c04a2de.
1 parent c04a2de commit facf66b

13 files changed

+56
-178
lines changed

project_task_code/README.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
Sequential Code for Tasks
33
=========================
44

5-
..
6-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76
!! This file is generated by oca-gen-addon-readme !!
87
!! changes will be overwritten. !!
98
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:28fcd535608cf7941d0c7cae839e6e0a5b226e3bce1968cde58bdac4eaced570
11-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
129
1310
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1411
:target: https://odoo-community.org/page/development-status
@@ -23,10 +20,10 @@ Sequential Code for Tasks
2320
:target: https://translation.odoo-community.org/projects/project-16-0/project-16-0-project_task_code
2421
:alt: Translate me on Weblate
2522
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=16.0
23+
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/project&target_branch=16.0
2724
:alt: Try me on Runboat
2825

29-
|badge1| |badge2| |badge3| |badge4| |badge5|
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
3027

3128
This module adds a sequential code for tasks.
3229

@@ -38,8 +35,11 @@ This module adds a sequential code for tasks.
3835
Configuration
3936
=============
4037

41-
To check the task code unicity (recommended) check "Unique Task Code"
42-
in the settings of the Project app.
38+
To change the task code sequence, you must:
39+
40+
#. Activate the developer mode.
41+
#. Go to Settings > Technical > Sequences & Identifiers > Sequences.
42+
#. Click on "Task code" sequence to edit.
4343

4444
Usage
4545
=====
@@ -55,7 +55,7 @@ Bug Tracker
5555

5656
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/issues>`_.
5757
In case of trouble, please check there if your issue has already been reported.
58-
If you spotted it first, help us to smash it by providing a detailed and welcomed
58+
If you spotted it first, help us smashing it by providing a detailed and welcomed
5959
`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**>`_.
6060

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

project_task_code/__manifest__.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"data": [
1818
"data/task_sequence.xml",
1919
"views/project_view.xml",
20-
"views/res_config_settings_view.xml",
2120
],
2221
"installable": True,
2322
"pre_init_hook": "pre_init_hook",

project_task_code/hooks.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
from odoo import SUPERUSER_ID, api
55

6-
# todo add parameter constraint in migration
7-
# add param to view
8-
96

107
def pre_init_hook(cr):
118
"""

project_task_code/migrations/16.0.1.0.0/post-migration.py

-12
This file was deleted.

project_task_code/migrations/16.0.1.0.0/pre-migration.py

-12
This file was deleted.

project_task_code/models/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
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

+4-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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
65

76

87
class ProjectTask(models.Model):
@@ -16,6 +15,10 @@ class ProjectTask(models.Model):
1615
copy=False,
1716
)
1817

18+
_sql_constraints = [
19+
("project_task_unique_code", "UNIQUE (code)", _("The code must be unique!")),
20+
]
21+
1922
@api.model_create_multi
2023
def create(self, vals_list):
2124
for vals in vals_list:
@@ -34,28 +37,3 @@ def name_get(self):
3437
name = "[{}] {}".format(rec.code, task[1])
3538
new_result.append((rec.id, name))
3639
return new_result
37-
38-
@api.constrains("code")
39-
def _check_project_task_unique_code(self):
40-
unique_task_code = bool(
41-
self.env["ir.config_parameter"]
42-
.sudo()
43-
.get_param("project_task_code.unique_task_code")
44-
)
45-
if not unique_task_code:
46-
return
47-
48-
for task in self:
49-
if (
50-
task.code
51-
and task.code != "/"
52-
and self.search(
53-
[
54-
("code", "=", task.code),
55-
("id", "!=", task.id),
56-
("company_id", "=", task.company_id.id),
57-
],
58-
limit=1,
59-
)
60-
):
61-
raise ValidationError(_("The code must be unique!"))

project_task_code/models/res_config_settings.py

-13
This file was deleted.
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
To check the task code unicity (recommended) check "Unique Task Code"
2-
in the settings of the Project app.
1+
To change the task code sequence, you must:
2+
3+
#. Activate the developer mode.
4+
#. Go to Settings > Technical > Sequences & Identifiers > Sequences.
5+
#. Click on "Task code" sequence to edit.

project_task_code/static/description/index.html

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
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: https://docutils.sourceforge.io/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Sequential Code for Tasks</title>
88
<style type="text/css">
99

1010
/*
1111
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
12+
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
1313
:Copyright: This stylesheet has been placed in the public domain.
1414
1515
Default cascading style sheet for the HTML output of Docutils.
1616
17-
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
17+
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
1919
*/
2020

@@ -366,57 +366,59 @@ <h1 class="title">Sequential Code for Tasks</h1>
366366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:28fcd535608cf7941d0c7cae839e6e0a5b226e3bce1968cde58bdac4eaced570
371369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<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_code"><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_code"><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>
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>
373371
<p>This module adds a sequential code for tasks.</p>
374372
<p><strong>Table of contents</strong></p>
375373
<div class="contents local topic" id="contents">
376374
<ul class="simple">
377-
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
378-
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
379-
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
380-
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
381-
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
382-
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
383-
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
375+
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
376+
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
377+
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
378+
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
379+
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
380+
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
381+
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
384382
</ul>
385383
</li>
386384
</ul>
387385
</div>
388386
<div class="section" id="configuration">
389-
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
390-
<p>To check the task code unicity (recommended) check “Unique Task Code”
391-
in the settings of the Project app.</p>
387+
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
388+
<p>To change the task code sequence, you must:</p>
389+
<ol class="arabic simple">
390+
<li>Activate the developer mode.</li>
391+
<li>Go to Settings &gt; Technical &gt; Sequences &amp; Identifiers &gt; Sequences.</li>
392+
<li>Click on “Task code” sequence to edit.</li>
393+
</ol>
392394
</div>
393395
<div class="section" id="usage">
394-
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
396+
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
395397
<p>To use this module, you need to:</p>
396398
<p>#. Go to menu Project &gt; Search &gt; Tasks and create a new task, and you get a
397399
new code saving it.
398400
#. If you duplicate a task, you will get a new code for the new task.</p>
399401
</div>
400402
<div class="section" id="bug-tracker">
401-
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
403+
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
402404
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/project/issues">GitHub Issues</a>.
403405
In case of trouble, please check there if your issue has already been reported.
404-
If you spotted it first, help us to smash it by providing a detailed and welcomed
406+
If you spotted it first, help us smashing it by providing a detailed and welcomed
405407
<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>
406408
<p>Do not contact contributors directly about support or help with technical issues.</p>
407409
</div>
408410
<div class="section" id="credits">
409-
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
411+
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
410412
<div class="section" id="authors">
411-
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
413+
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
412414
<ul class="simple">
413415
<li>OdooMRP team</li>
414416
<li>AvanzOSC</li>
415417
<li>Tecnativa</li>
416418
</ul>
417419
</div>
418420
<div class="section" id="contributors">
419-
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
421+
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
420422
<ul class="simple">
421423
<li>Oihane Crucelaegui &lt;<a class="reference external" href="mailto:oihanecrucelaegi&#64;avanzosc.es">oihanecrucelaegi&#64;avanzosc.es</a>&gt;</li>
422424
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;serviciosbaeza.com">pedro.baeza&#64;serviciosbaeza.com</a>&gt;</li>
@@ -434,7 +436,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
434436
</ul>
435437
</div>
436438
<div class="section" id="maintainers">
437-
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
439+
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
438440
<p>This module is maintained by the OCA.</p>
439441
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
440442
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose

project_task_code/tests/test_project_task_code.py

+6-33
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
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
65

76

87
class TestProjectTaskCode(common.TransactionCase):
9-
@classmethod
10-
def setUpClass(cls):
11-
super().setUpClass()
12-
cls.project_task_model = cls.env["project.task"]
13-
cls.ir_sequence_model = cls.env["ir.sequence"]
14-
cls.task_sequence = cls.env.ref("project_task_code.sequence_task")
15-
cls.project_task = cls.env.ref("project.project_1_task_1")
8+
def setUp(self):
9+
super().setUp()
10+
self.project_task_model = self.env["project.task"]
11+
self.ir_sequence_model = self.env["ir.sequence"]
12+
self.task_sequence = self.env.ref("project_task_code.sequence_task")
13+
self.project_task = self.env.ref("project.project_1_task_1")
1614

1715
def test_old_task_code_assign(self):
1816
project_tasks = self.project_task_model.search([])
@@ -40,28 +38,3 @@ def test_name_get(self):
4038
)
4139
result = project_task.name_get()
4240
self.assertEqual(result[0][1], "[%s] Task Testing Get Name" % code)
43-
44-
def test_unique_task_code(self):
45-
task_1 = self.project_task_model.create(
46-
{
47-
"name": "Task 1",
48-
}
49-
)
50-
task_2 = self.project_task_model.create(
51-
{
52-
"name": "Task 2",
53-
}
54-
)
55-
task_3 = self.project_task_model.create(
56-
{
57-
"name": "Task 3",
58-
}
59-
)
60-
# by default, unicity is not checked
61-
task_2.code = task_1.code
62-
63-
self.env["ir.config_parameter"].sudo().set_param(
64-
"project_task_code.unique_task_code", True
65-
)
66-
with self.assertRaises(ValidationError, msg="The code must be unique!"):
67-
task_3.code = task_1.code

project_task_code/views/project_view.xml

+6-17
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
<field name="inherit_id" ref="project.view_task_form2" />
77
<field name="arch" type="xml">
88
<field name="name" position="before">
9-
<field
10-
name="code"
11-
class="oe_inline"
12-
attrs="{'invisible': [('code', 'in', ['/', False])]}"
13-
/>
14-
<span
15-
class="oe_inline"
16-
attrs="{'invisible': [('code', 'in', ['/', False])]}"
17-
> - </span>
9+
<field name="code" class="oe_inline" />
10+
<span class="oe_inline"> - </span>
1811
</field>
1912
</field>
2013
</record>
@@ -24,7 +17,7 @@
2417
<field name="inherit_id" ref="project.view_task_tree2" />
2518
<field name="arch" type="xml">
2619
<field name="name" position="before">
27-
<field name="code" optional="hide" />
20+
<field name="code" />
2821
</field>
2922
</field>
3023
</record>
@@ -33,13 +26,9 @@
3326
<field name="model">project.task</field>
3427
<field name="inherit_id" ref="project.view_task_kanban" />
3528
<field name="arch" type="xml">
36-
<xpath expr="//field[@name='name']/.." position="before">
37-
<field
38-
name="code"
39-
class="me-2"
40-
attrs="{'invisible': [('code', '=', '/')]}"
41-
/>
42-
</xpath>
29+
<field name="name" position="before">
30+
<field name="code" />
31+
</field>
4332
</field>
4433
</record>
4534
<record id="project_task_code_search_view" model="ir.ui.view">

0 commit comments

Comments
 (0)