Skip to content

Commit ad29b91

Browse files
petrus-vdreispt
authored andcommitted
[MIG] project_analytic_code: Migration to 17.0
1 parent 08e00a6 commit ad29b91

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

project_analytic_code/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"author": "Pierre Verkest, Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/project",
99
"category": "Project Management",
10-
"version": "14.0.1.0.0",
10+
"version": "17.0.0.1.0",
1111
"license": "AGPL-3",
1212
"depends": [
1313
"project",

project_analytic_code/models/project.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@
77
class Project(models.Model):
88
_inherit = "project.project"
99

10+
_rec_names_search = [
11+
"name",
12+
"analytic_account_code",
13+
]
14+
1015
analytic_account_code = fields.Char(
1116
string="Analytic code",
1217
related="analytic_account_id.code",
1318
store=True,
14-
index=True,
19+
index="btree_not_null",
1520
)
1621

17-
@api.model
18-
def name_search(self, name="", args=None, operator="ilike", limit=100):
19-
args = list(args or [])
20-
if name:
21-
args += ["|", ("analytic_account_code", "=", name)]
22-
return super().name_search(name=name, args=args, operator=operator, limit=limit)
23-
24-
def name_get(self):
25-
result = super().name_get()
26-
# Prepend analytic_account_code to display_name
27-
for i, (res_item, project) in enumerate(zip(result, self)):
22+
@api.depends("analytic_account_code")
23+
def _compute_display_name(self):
24+
# res is null but avoid noqa: W8110
25+
res = super()._compute_display_name()
26+
for project in self:
2827
code = project.analytic_account_code
2928
if code:
30-
result[i] = (res_item[0], "[%s] %s" % (code, res_item[1]))
31-
return result
29+
project.display_name = f"[{code}] {project.display_name}"
30+
return res

project_analytic_code/tests/test_project.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

44
from odoo.tests import tagged
5-
from odoo.tests.common import SavepointCase
5+
from odoo.tests.common import TransactionCase
66

77

88
@tagged("post_install", "-at_install")
9-
class TestProject(SavepointCase):
9+
class TestProject(TransactionCase):
1010
@classmethod
1111
def setUpClass(cls):
1212
super().setUpClass()
1313
cls.project = cls.env.ref("project.project_project_1")
1414
cls.project.name = "Test project name"
15+
cls.plan = cls.env["account.analytic.plan"].create({"name": "Test plan"})
1516
cls.project.analytic_account_id = cls.env["account.analytic.account"].create(
16-
{"name": "Test Analytic account name", "code": "Test Weird code"}
17+
{
18+
"name": "Test Analytic account name",
19+
"code": "Test Weird code",
20+
"plan_id": cls.plan.id,
21+
}
1722
)
1823

1924
def test_search_project_by_account_analytic_code(self):
@@ -24,3 +29,15 @@ def test_search_project_by_account_analytic_code(self):
2429
result[0][1],
2530
f"[{self.project.analytic_account_id.code}] {self.project.name}",
2631
)
32+
33+
def test_project_display_name(self):
34+
self.assertEqual(
35+
self.project.display_name,
36+
f"[{self.project.analytic_account_id.code}] {self.project.name}",
37+
)
38+
self.project.analytic_account_id = False
39+
40+
self.assertEqual(
41+
self.project.display_name,
42+
f"{self.project.name}",
43+
)
Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,23 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
<data>
4-
<record id="view_project_project_filter" model="ir.ui.view">
5-
<field name="inherit_id" ref="project.view_project_project_filter" />
6-
<field name="name">project_analytic_code.project.select</field>
7-
<field name="model">project.project</field>
8-
<field name="arch" type="xml">
9-
<field name="name" position="attributes">
10-
<attribute
11-
name="filter_domain"
12-
>["|", ("name", "ilike", self), ("analytic_account_code", "=", self)]</attribute>
13-
</field>
14-
<xpath expr="//group" position="inside">
15-
<filter
16-
string="Analytic account"
17-
name="Analytic account"
18-
context="{'group_by': 'analytic_account_id'}"
19-
/>
20-
</xpath>
3+
<record id="view_project_project_filter" model="ir.ui.view">
4+
<field name="inherit_id" ref="project.view_project_project_filter" />
5+
<field name="name">project_analytic_code.project.select</field>
6+
<field name="model">project.project</field>
7+
<field name="arch" type="xml">
8+
<field name="name" position="attributes">
9+
<attribute
10+
name="filter_domain"
11+
>["|", ("name", "ilike", self), ("analytic_account_code", "=", self)]</attribute>
2112
</field>
22-
</record>
13+
<xpath expr="//group" position="inside">
14+
<filter
15+
string="Analytic account"
16+
name="Analytic account"
17+
context="{'group_by': 'analytic_account_id'}"
18+
/>
19+
</xpath>
20+
</field>
21+
</record>
2322

24-
<record model="ir.ui.view" id="view_project_kanban">
25-
<field name="inherit_id" ref="project.view_project_kanban" />
26-
<field name="name">project.project.kanban.project_analytic_code</field>
27-
<field name="model">project.project</field>
28-
<field name="priority">200</field>
29-
<field name="arch" type="xml">
30-
<field name="name" position="after">
31-
<field name="analytic_account_code" />
32-
</field>
33-
<xpath expr="//t[@t-esc='record.name.value']" position="before">
34-
<strong t-if="record.analytic_account_code.value">
35-
[<t t-esc="record.analytic_account_code.value" />]
36-
</strong>
37-
</xpath>
38-
</field>
39-
</record>
40-
</data>
4123
</odoo>

0 commit comments

Comments
 (0)