Skip to content

Commit

Permalink
[MIG] account_financial_report: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiadavid committed Dec 24, 2022
1 parent 40d715e commit 36c5b35
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 318 deletions.
11 changes: 4 additions & 7 deletions account_financial_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Financial Reports",
"version": "15.0.2.3.0",
"version": "16.0.1.0.0",
"category": "Reporting",
"summary": "OCA Financial Reports",
"author": "Camptocamp SA,"
Expand Down Expand Up @@ -43,14 +43,11 @@
],
"assets": {
"web.assets_backend": [
"account_financial_report/static/src/js/action_manager_report.js",
"account_financial_report/static/src/js/client_action.js",
"account_financial_report/static/src/js/report_action.esm.js",
"account_financial_report/static/src/xml/**/*",
],
"web.report_assets_common": [
"account_financial_report/static/src/js/report.js"
],
"web.assets_qweb": [
"account_financial_report/static/src/xml/**/*",
"account_financial_report/static/src/js/report.js",
],
},
"installable": True,
Expand Down
24 changes: 21 additions & 3 deletions account_financial_report/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
from odoo import api, models
from odoo import api, fields, 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):
for record in self:
if not record.analytic_distribution:
record.analytic_account_ids = False
else:
record.update(
{
"analytic_account_ids": [
(6, 0, [int(k) for k in record.analytic_distribution])
]
}
)

def init(self):
"""
The join between accounts_partners subquery and account_move_line
Expand All @@ -32,9 +50,9 @@ def init(self):
)

@api.model
def search_count(self, args):
def search_count(self, domain, limit=None):
# In Big DataBase every time you change the domain widget this method
# takes a lot of time. This improves performance
if self.env.context.get("skip_search_count"):
return 0
return super(AccountMoveLine, self).search_count(args)
return super().search_count(domain, limit=limit)
10 changes: 6 additions & 4 deletions account_financial_report/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ def _prepare_account_financial_report_context(self, data):
return dict(self.env.context or {}, lang=lang) if lang else False

@api.model
def _render_qweb_html(self, docids, data=None):
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(docids, data)
return super(IrActionsReport, obj)._render_qweb_html(
report_ref, docids, data=data
)

@api.model
def _render_xlsx(self, docids, data):
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(docids, data)
return super(IrActionsReport, obj)._render_xlsx(report_ref, docids, data=data)
85 changes: 35 additions & 50 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class GeneralLedgerReport(models.AbstractModel):
_description = "General Ledger Report"
_inherit = "report.account_financial_report.abstract_report"

def _get_tags_data(self, tags_ids):
tags = self.env["account.analytic.tag"].browse(tags_ids)
tags_data = {}
for tag in tags:
tags_data.update({tag.id: {"name": tag.name}})
return tags_data
def _get_analytic_data(self, account_ids):
analytic_accounts = self.env["account.analytic.account"].browse(account_ids)
analytic_data = {}
for account in analytic_accounts:
analytic_data.update({account.id: {"name": account.name}})
return analytic_data

def _get_taxes_data(self, taxes_ids):
taxes = self.env["account.tax"].browse(taxes_ids)
Expand Down Expand Up @@ -51,12 +51,16 @@ def _get_taxes_data(self, taxes_ids):
return taxes_data

def _get_account_internal_types(self, grouped_by):
return ["receivable", "payable"] if grouped_by != "taxes" else ["other"]
return (
["asset_receivable", "liability_payable"]
if grouped_by != "taxes"
else ["other"]
)

def _get_acc_prt_accounts_ids(self, company_id, grouped_by):
accounts_domain = [
("company_id", "=", company_id),
("internal_type", "in", self._get_account_internal_types(grouped_by)),
("account_type", "in", self._get_account_internal_types(grouped_by)),
]
acc_prt_accounts = self.env["account.account"].search(accounts_domain)
return acc_prt_accounts.ids
Expand All @@ -66,7 +70,7 @@ def _get_initial_balances_bs_ml_domain(
):
accounts_domain = [
("company_id", "=", company_id),
("user_type_id.include_initial_balance", "=", True),
("include_initial_balance", "=", True),
]
if account_ids:
accounts_domain += [("id", "in", account_ids)]
Expand All @@ -77,15 +81,15 @@ def _get_initial_balances_bs_ml_domain(
domain += [("account_id", "in", accounts.ids)]
if acc_prt:
internal_types = self._get_account_internal_types(grouped_by)
domain += [("account_id.internal_type", "in", internal_types)]
domain += [("account_type", "in", internal_types)]
return domain

def _get_initial_balances_pl_ml_domain(
self, account_ids, company_id, date_from, fy_start_date, base_domain
):
accounts_domain = [
("company_id", "=", company_id),
("user_type_id.include_initial_balance", "=", False),
("include_initial_balance", "=", False),
]
if account_ids:
accounts_domain += [("id", "in", account_ids)]
Expand All @@ -99,12 +103,12 @@ def _get_initial_balances_pl_ml_domain(
def _get_accounts_initial_balance(self, initial_domain_bs, initial_domain_pl):
gl_initial_acc_bs = self.env["account.move.line"].read_group(
domain=initial_domain_bs,
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
groupby=["account_id"],
)
gl_initial_acc_pl = self.env["account.move.line"].read_group(
domain=initial_domain_pl,
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
groupby=["account_id"],
)
gl_initial_acc = gl_initial_acc_bs + gl_initial_acc_pl
Expand All @@ -115,7 +119,7 @@ def _get_initial_balance_fy_pl_ml_domain(
):
accounts_domain = [
("company_id", "=", company_id),
("user_type_id.include_initial_balance", "=", False),
("include_initial_balance", "=", False),
]
if account_ids:
accounts_domain += [("id", "in", account_ids)]
Expand All @@ -134,7 +138,7 @@ def _get_pl_initial_balance(
)
initial_balances = self.env["account.move.line"].read_group(
domain=domain,
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
groupby=["account_id"],
)
pl_initial_balance = {
Expand Down Expand Up @@ -192,7 +196,7 @@ def _prepare_gen_ld_data_group_partners(self, data, domain, grouped_by):
"debit",
"credit",
"balance",
"amount_currency",
"amount_currency:sum",
],
groupby=["account_id", "partner_id"],
lazy=False,
Expand Down Expand Up @@ -221,7 +225,7 @@ def _prepare_gen_ld_data_group_taxes(self, data, domain, grouped_by):
"debit",
"credit",
"balance",
"amount_currency",
"amount_currency:sum",
"tax_line_id",
],
groupby=["account_id"],
Expand Down Expand Up @@ -253,7 +257,6 @@ def _get_initial_balance_data(
only_posted_moves,
unaffected_earnings_account,
fy_start_date,
analytic_tag_ids,
cost_center_ids,
extra_domain,
grouped_by,
Expand All @@ -271,10 +274,8 @@ def _get_initial_balance_data(
base_domain += [("move_id.state", "=", "posted")]
else:
base_domain += [("move_id.state", "in", ["posted", "draft"])]
if analytic_tag_ids:
base_domain += [("analytic_tag_ids", "in", analytic_tag_ids)]
if cost_center_ids:
base_domain += [("analytic_account_id", "in", 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 @@ -335,14 +336,8 @@ def _get_move_line_data(self, move_line):
"rec_name": move_line["full_reconcile_id"][1]
if move_line["full_reconcile_id"]
else "",
"tag_ids": move_line["analytic_tag_ids"],
"currency_id": move_line["currency_id"],
"analytic_account": move_line["analytic_account_id"][1]
if move_line["analytic_account_id"]
else "",
"analytic_account_id": move_line["analytic_account_id"][0]
if move_line["analytic_account_id"]
else False,
"analytic_distribution": move_line["analytic_distribution"] or {},
}
if (
move_line_data["ref"] == move_line_data["name"]
Expand All @@ -365,11 +360,10 @@ def _get_period_domain(
only_posted_moves,
date_to,
date_from,
analytic_tag_ids,
cost_center_ids,
):
domain = [
("display_type", "=", False),
("display_type", "not in", ["line_note", "line_section"]),
("date", ">=", date_from),
("date", "<=", date_to),
]
Expand All @@ -383,10 +377,9 @@ def _get_period_domain(
domain += [("move_id.state", "=", "posted")]
else:
domain += [("move_id.state", "in", ["posted", "draft"])]
if analytic_tag_ids:
domain += [("analytic_tag_ids", "in", analytic_tag_ids)]

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

def _initialize_data(self, foreign_currency):
Expand Down Expand Up @@ -450,7 +443,6 @@ def _get_period_ml_data(
date_from,
date_to,
gen_ld_data,
analytic_tag_ids,
cost_center_ids,
extra_domain,
grouped_by,
Expand All @@ -462,7 +454,6 @@ def _get_period_ml_data(
only_posted_moves,
date_to,
date_from,
analytic_tag_ids,
cost_center_ids,
)
if extra_domain:
Expand All @@ -482,27 +473,26 @@ def _get_period_ml_data(
"full_reconcile_id",
"tax_ids",
"tax_line_id",
"analytic_tag_ids",
"amount_currency",
"ref",
"name",
"analytic_account_id",
"analytic_distribution",
]
move_lines = self.env["account.move.line"].search_read(
domain=domain, fields=ml_fields
)
journal_ids = set()
full_reconcile_ids = set()
taxes_ids = set()
tags_ids = set()
analytic_ids = set()
full_reconcile_data = {}
acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_id, grouped_by)
for move_line in move_lines:
journal_ids.add(move_line["journal_id"][0])
for tax_id in move_line["tax_ids"]:
taxes_ids.add(tax_id)
for analytic_tag_id in move_line["analytic_tag_ids"]:
tags_ids.add(analytic_tag_id)
for analytic_account in move_line["analytic_distribution"] or {}:
analytic_ids.add(int(analytic_account))
if move_line["full_reconcile_id"]:
rec_id = move_line["full_reconcile_id"][0]
if rec_id not in full_reconcile_ids:
Expand Down Expand Up @@ -563,7 +553,7 @@ def _get_period_ml_data(
journals_data = self._get_journals_data(list(journal_ids))
accounts_data = self._get_accounts_data(gen_ld_data.keys())
taxes_data = self._get_taxes_data(list(taxes_ids))
tags_data = self._get_tags_data(list(tags_ids))
analytic_data = self._get_analytic_data(list(analytic_ids))
rec_after_date_to_ids = self._get_reconciled_after_date_to_ids(
full_reconcile_data.keys(), date_to
)
Expand All @@ -573,7 +563,7 @@ def _get_period_ml_data(
journals_data,
full_reconcile_data,
taxes_data,
tags_data,
analytic_data,
rec_after_date_to_ids,
)

Expand Down Expand Up @@ -756,9 +746,8 @@ def _calculate_centralization(self, centralized_ml, move_line, date_to):
"tax_line_id": False,
"full_reconcile_id": False,
"id": False,
"tag_ids": False,
"currency_id": False,
"analytic_account_id": False,
"analytic_distribution": {},
}
)
centralized_ml[jnl_id][month]["debit"] += move_line["debit"]
Expand Down Expand Up @@ -802,7 +791,6 @@ def _get_report_values(self, docids, data):
date_from = data["date_from"]
partner_ids = data["partner_ids"]
account_ids = data["account_ids"]
analytic_tag_ids = data["analytic_tag_ids"]
cost_center_ids = data["cost_center_ids"]
grouped_by = data["grouped_by"]
hide_account_at_0 = data["hide_account_at_0"]
Expand All @@ -820,7 +808,6 @@ def _get_report_values(self, docids, data):
only_posted_moves,
unaffected_earnings_account,
fy_start_date,
analytic_tag_ids,
cost_center_ids,
extra_domain,
grouped_by,
Expand All @@ -832,7 +819,7 @@ def _get_report_values(self, docids, data):
journals_data,
full_reconcile_data,
taxes_data,
tags_data,
analytic_data,
rec_after_date_to_ids,
) = self._get_period_ml_data(
account_ids,
Expand All @@ -843,7 +830,6 @@ def _get_report_values(self, docids, data):
date_from,
date_to,
gen_ld_data,
analytic_tag_ids,
cost_center_ids,
extra_domain,
grouped_by,
Expand Down Expand Up @@ -883,15 +869,14 @@ def _get_report_values(self, docids, data):
"date_to": data["date_to"],
"only_posted_moves": data["only_posted_moves"],
"hide_account_at_0": data["hide_account_at_0"],
"show_analytic_tags": data["show_analytic_tags"],
"show_cost_center": data["show_cost_center"],
"general_ledger": general_ledger,
"accounts_data": accounts_data,
"journals_data": journals_data,
"full_reconcile_data": full_reconcile_data,
"taxes_data": taxes_data,
"centralize": centralize,
"tags_data": tags_data,
"analytic_data": analytic_data,
"filter_partner_ids": True if partner_ids else False,
"currency_model": self.env["res.currency"],
}
Loading

0 comments on commit 36c5b35

Please sign in to comment.