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

[16.0][IMP] account_financial_report: Several improvements #1081

Draft
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
31 changes: 1 addition & 30 deletions account_financial_report/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
from collections import defaultdict

from odoo import api, fields, models
from odoo import api, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

analytic_account_ids = fields.Many2many(
"account.analytic.account", compute="_compute_analytic_account_ids", store=True
)

@api.depends("analytic_distribution")
def _compute_analytic_account_ids(self):
# Prefetch all involved analytic accounts
with_distribution = self.filtered("analytic_distribution")
batch_by_analytic_account = defaultdict(list)
for record in with_distribution:
for account_id in map(int, record.analytic_distribution):
batch_by_analytic_account[account_id].append(record.id)
existing_account_ids = set(
self.env["account.analytic.account"]
.browse(map(int, batch_by_analytic_account))
.exists()
.ids
)
# Store them
self.analytic_account_ids = False
for account_id, record_ids in batch_by_analytic_account.items():
if account_id not in existing_account_ids:
continue
self.browse(record_ids).analytic_account_ids = [
fields.Command.link(account_id)
]

def init(self):
"""
The join between accounts_partners subquery and account_move_line
Expand Down
5 changes: 0 additions & 5 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ def _get_initial_balance_data(
base_domain += [("move_id.state", "=", "posted")]
else:
base_domain += [("move_id.state", "in", ["posted", "draft"])]
if cost_center_ids:
base_domain += [("analytic_account_ids", "in", cost_center_ids)]
if extra_domain:
base_domain += extra_domain
gl_initial_acc = self._get_gl_initial_acc(
Expand Down Expand Up @@ -377,9 +375,6 @@ def _get_period_domain(
domain += [("move_id.state", "=", "posted")]
else:
domain += [("move_id.state", "in", ["posted", "draft"])]

if cost_center_ids:
domain += [("analytic_account_ids", "in", cost_center_ids)]
return domain

def _initialize_data(self, foreign_currency):
Expand Down
31 changes: 19 additions & 12 deletions account_financial_report/wizard/general_ledger_wizard_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,30 @@
</group>
</page>
<page string="Filter partners">
<field
name="partner_ids"
nolabel="1"
widget="many2many_tags"
options="{'no_create': True}"
/>
<group>
<group>
<field
name="partner_ids"
widget="many2many_tags"
options="{'no_create': True}"
/>
</group>
</group>
</page>
<page
string="Filter analytic accounts"
groups="analytic.group_analytic_accounting"
>
<field
name="cost_center_ids"
nolabel="1"
widget="many2many_tags"
options="{'no_create': True}"
/>
<group>
<group>
<field
name="cost_center_ids"
widget="many2many_tags"
options="{'no_create': True}"
/>
</group>
</group>

</page>
<page string="Additional Filtering">
<style>
Expand Down
Loading