Skip to content

Commit

Permalink
[PoC] Proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
BernatObrador committed Jan 21, 2025
1 parent ee95c7e commit 13afe8e
Show file tree
Hide file tree
Showing 21 changed files with 1,221 additions and 170 deletions.
1 change: 1 addition & 0 deletions account_analytic_report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import models
from . import report
from . import wizard
3 changes: 2 additions & 1 deletion account_analytic_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "APSL-Nagarro, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"category": "Account",
"depends": ["analytic", "account_financial_report"],
"depends": ["account", "date_range", "report_xlsx"],
"maintainers": ["BernatObrador", "miquelalzanillas"],
"data": [
"security/ir.model.access.csv",
Expand All @@ -17,6 +17,7 @@
"report/templates/trial_balance_analytic.xml",
"views/report_trial_balance_analytic.xml",
"views/account_analytic_line.xml",
"report/templates/layouts.xml",
],
"assets": {
"web.assets_backend": [
Expand Down
2 changes: 2 additions & 0 deletions account_analytic_report/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_group
from . import ir_actions_report
67 changes: 67 additions & 0 deletions account_analytic_report/models/account_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ?? 2018 Forest and Biomass Romania SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountGroup(models.Model):
_inherit = "account.group"

group_child_ids = fields.One2many(
comodel_name="account.group", inverse_name="parent_id", string="Child Groups"
)
level = fields.Integer(compute="_compute_level", recursive=True)
account_ids = fields.One2many(
comodel_name="account.account", inverse_name="group_id", string="Accounts"
)
compute_account_ids = fields.Many2many(
"account.account",
recursive=True,
compute="_compute_group_accounts",
string="Compute accounts",
store=True,
)
complete_name = fields.Char(
"Full Name", compute="_compute_complete_name", recursive=True
)
complete_code = fields.Char(
"Full Code", compute="_compute_complete_code", recursive=True
)

@api.depends("name", "parent_id.complete_name")
def _compute_complete_name(self):
"""Forms complete name of location from parent location to child location."""
for group in self:
if group.parent_id.complete_name:
group.complete_name = f"{group.parent_id.complete_name}/{group.name}"

Check warning on line 36 in account_analytic_report/models/account_group.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_report/models/account_group.py#L36

Added line #L36 was not covered by tests
else:
group.complete_name = group.name

Check warning on line 38 in account_analytic_report/models/account_group.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_report/models/account_group.py#L38

Added line #L38 was not covered by tests

@api.depends("code_prefix_start", "parent_id.complete_code")
def _compute_complete_code(self):
"""Forms complete code of location from parent location to child location."""
for group in self:
if group.parent_id.complete_code:
group.complete_code = "{}/{}".format(
group.parent_id.complete_code, group.code_prefix_start
)
else:
group.complete_code = group.code_prefix_start

@api.depends("parent_id", "parent_id.level")
def _compute_level(self):
for group in self:
if not group.parent_id:
group.level = 0

Check warning on line 55 in account_analytic_report/models/account_group.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_report/models/account_group.py#L55

Added line #L55 was not covered by tests
else:
group.level = group.parent_id.level + 1

Check warning on line 57 in account_analytic_report/models/account_group.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_report/models/account_group.py#L57

Added line #L57 was not covered by tests

@api.depends(
"account_ids",
"group_child_ids.compute_account_ids",
)
def _compute_group_accounts(self):
for one in self:
one.compute_account_ids = (
one.account_ids | one.group_child_ids.compute_account_ids
)
27 changes: 27 additions & 0 deletions account_analytic_report/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2020 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class IrActionsReport(models.Model):
_inherit = "ir.actions.report"

@api.model
def _prepare_account_financial_report_context(self, data):
lang = data and data.get("account_financial_report_lang") or ""
return dict(self.env.context or {}, lang=lang) if lang else False

@api.model
def _render_qweb_html(self, report_ref, docids, data=None):
context = self._prepare_account_financial_report_context(data)
obj = self.with_context(**context) if context else self
return super(IrActionsReport, obj)._render_qweb_html(
report_ref, docids, data=data
)

@api.model
def _render_xlsx(self, report_ref, docids, data=None):
context = self._prepare_account_financial_report_context(data)
obj = self.with_context(**context) if context else self
return super(IrActionsReport, obj)._render_xlsx(report_ref, docids, data=data)

Check warning on line 27 in account_analytic_report/models/ir_actions_report.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_report/models/ir_actions_report.py#L25-L27

Added lines #L25 - L27 were not covered by tests
1 change: 1 addition & 0 deletions account_analytic_report/report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import abstract_report_xlsx
from . import trial_balance_analytic
from . import trial_balance_analytic_xlsx
Loading

0 comments on commit 13afe8e

Please sign in to comment.