Skip to content

Commit

Permalink
[MIG] project_analytic_code: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
petrus-v committed Feb 18, 2025
1 parent 3076934 commit a19c761
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
2 changes: 1 addition & 1 deletion project_analytic_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Pierre Verkest, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/project",
"category": "Project Management",
"version": "14.0.1.0.0",
"version": "17.0.0.1.0",
"license": "AGPL-3",
"depends": [
"project",
Expand Down
27 changes: 13 additions & 14 deletions project_analytic_code/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@
class Project(models.Model):
_inherit = "project.project"

_rec_names_search = [
"name",
"analytic_account_code",
]

analytic_account_code = fields.Char(
string="Analytic code",
related="analytic_account_id.code",
store=True,
index=True,
index="btree_not_null",
)

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
args = list(args or [])
if name:
args += ["|", ("analytic_account_code", "=", name)]
return super().name_search(name=name, args=args, operator=operator, limit=limit)

def name_get(self):
result = super().name_get()
# Prepend analytic_account_code to display_name
for i, (res_item, project) in enumerate(zip(result, self)):
@api.depends("analytic_account_code")
def _compute_display_name(self):
# res is null but avoid noqa: W8110
res = super()._compute_display_name()
for project in self:
code = project.analytic_account_code
if code:
result[i] = (res_item[0], "[%s] %s" % (code, res_item[1]))
return result
project.display_name = f"[{code}] {project.display_name}"
return res
23 changes: 20 additions & 3 deletions project_analytic_code/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import tagged
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


@tagged("post_install", "-at_install")
class TestProject(SavepointCase):
class TestProject(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.project = cls.env.ref("project.project_project_1")
cls.project.name = "Test project name"
cls.plan = cls.env["account.analytic.plan"].create({"name": "Test plan"})
cls.project.analytic_account_id = cls.env["account.analytic.account"].create(
{"name": "Test Analytic account name", "code": "Test Weird code"}
{
"name": "Test Analytic account name",
"code": "Test Weird code",
"plan_id": cls.plan.id,
}
)

def test_search_project_by_account_analytic_code(self):
Expand All @@ -24,3 +29,15 @@ def test_search_project_by_account_analytic_code(self):
result[0][1],
f"[{self.project.analytic_account_id.code}] {self.project.name}",
)

def test_project_display_name(self):
self.assertEqual(
self.project.display_name,
f"[{self.project.analytic_account_id.code}] {self.project.name}",
)
self.project.analytic_account_id = False

self.assertEqual(
self.project.display_name,
f"{self.project.name}",
)
54 changes: 18 additions & 36 deletions project_analytic_code/views/project.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="view_project_project_filter" model="ir.ui.view">
<field name="inherit_id" ref="project.view_project_project_filter" />
<field name="name">project_analytic_code.project.select</field>
<field name="model">project.project</field>
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute
name="filter_domain"
>["|", ("name", "ilike", self), ("analytic_account_code", "=", self)]</attribute>
</field>
<xpath expr="//group" position="inside">
<filter
string="Analytic account"
name="Analytic account"
context="{'group_by': 'analytic_account_id'}"
/>
</xpath>
<record id="view_project_project_filter" model="ir.ui.view">
<field name="inherit_id" ref="project.view_project_project_filter" />
<field name="name">project_analytic_code.project.select</field>
<field name="model">project.project</field>
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute
name="filter_domain"
>["|", ("name", "ilike", self), ("analytic_account_code", "=", self)]</attribute>
</field>
</record>
<xpath expr="//group" position="inside">
<filter
string="Analytic account"
name="Analytic account"
context="{'group_by': 'analytic_account_id'}"
/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="view_project_kanban">
<field name="inherit_id" ref="project.view_project_kanban" />
<field name="name">project.project.kanban.project_analytic_code</field>
<field name="model">project.project</field>
<field name="priority">200</field>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="analytic_account_code" />
</field>
<xpath expr="//t[@t-esc='record.name.value']" position="before">
<strong t-if="record.analytic_account_code.value">
[<t t-esc="record.analytic_account_code.value" />]
</strong>
</xpath>
</field>
</record>
</data>
</odoo>

0 comments on commit a19c761

Please sign in to comment.