Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] analytic_tag_dimension: Dynamic search view #736

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion analytic_tag_dimension/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,55 @@
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
from lxml import etree

from odoo import api, models


class AccountMoveLine(models.Model):
_name = "account.move.line"
_inherit = ["analytic.dimension.line", "account.move.line"]
_analytic_tag_field_name = "analytic_tag_ids"

@api.model
def _add_dimension_filters(self, res):
arch = etree.fromstring(res["arch"])
node_search = arch.xpath("//field[@name='journal_id']")
node_filter = arch.xpath("//filter[@name='groupby_date']")

Check warning on line 19 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L17-L19

Added lines #L17 - L19 were not covered by tests
for dimension in self.env["account.analytic.dimension"].search([]):
fieldname = dimension.get_field_name()

Check warning on line 21 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L21

Added line #L21 was not covered by tests
if node_search:
elem = etree.Element(

Check warning on line 23 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L23

Added line #L23 was not covered by tests
"field",
{
"name": fieldname,
"string": dimension.name,
"domain": "[('analytic_dimension_id', '=', %d)]" % dimension.id,
},
)
node_search[0].addnext(elem)

Check warning on line 31 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L31

Added line #L31 was not covered by tests
if node_filter:
elem = etree.Element(

Check warning on line 33 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L33

Added line #L33 was not covered by tests
"filter",
{
"name": "groupby_%s" % fieldname,
"string": dimension.name,
"domain": "[]",
"context": "{'group_by' : '%s'}" % fieldname,
},
)
node_filter[0].addnext(elem)
res["arch"] = etree.tostring(arch)
return res

Check warning on line 44 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L42-L44

Added lines #L42 - L44 were not covered by tests

@api.model
def fields_view_get(
self, view_id=None, view_type="form", toolbar=False, submenu=False
):
"""Inject dimension fields in search views."""
res = super().fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
if view_type == "search":
res = self._add_dimension_filters(res)

Check warning on line 55 in analytic_tag_dimension/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension/models/account_move_line.py#L55

Added line #L55 was not covered by tests
return res
Loading