[MIG] account_financial_report: Migration to 18.0

This commit is contained in:
chaule97
2024-11-18 16:48:37 +07:00
parent c46e83a4a4
commit 01f22b8256
43 changed files with 292 additions and 220 deletions

View File

@@ -1,6 +1,6 @@
# ?? 2015 Yannick Vaucher (Camptocamp)
# ?? 2016 Damien Crier (Camptocamp)
# ?? 2016 Julien Coux (Camptocamp)
# © 2015 Yannick Vaucher (Camptocamp)
# © 2016 Damien Crier (Camptocamp)
# © 2016 Julien Coux (Camptocamp)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
from . import abstract_report

View File

@@ -143,7 +143,9 @@ class AgedPartnerBalanceReport(models.AbstractModel):
return accounts_data
def _get_journals_data(self, journals_ids):
journals = self.env["account.journal"].browse(journals_ids)
journals = self.env["account.journal"].search_fetch(
[("id", "in", journals_ids)], ["code"]
)
journals_data = {}
for journal in journals:
journals_data.update({journal.id: {"id": journal.id, "code": journal.code}})

View File

@@ -1,6 +1,6 @@
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
@@ -571,7 +571,7 @@ class AbstractReportXslx(models.AbstractModel):
"""Return amount header format for each currency."""
format_amt = report_data["formats"]["format_header_amount"]
if line_object.currency_id:
field_name = "format_header_amount_%s" % line_object.currency_id.name
field_name = f"format_header_amount_{line_object.currency_id.name}"
if hasattr(self, field_name):
format_amt = getattr(self, field_name)
else:
@@ -589,7 +589,7 @@ class AbstractReportXslx(models.AbstractModel):
"""Return amount header format for each currency."""
format_amt = report_data["formats"]["format_header_amount"]
if line_object["currency_id"]:
field_name = "format_header_amount_%s" % line_object["currency_name"]
field_name = f"format_header_amount_{line_object['currency_name']}"
if hasattr(self, field_name):
format_amt = getattr(self, field_name)
else:

View File

@@ -1,4 +1,4 @@
# ?? 2016 Julien Coux (Camptocamp)
# © 2016 Julien Coux (Camptocamp)
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -72,25 +72,21 @@ class AgedPartnerBalanceReport(models.AbstractModel):
else:
ag_pb_data[acc_id]["older"] += residual
ag_pb_data[acc_id][prt_id]["older"] += residual
if due_date:
days_difference = abs((today - due_date).days)
for index, line in enumerate(interval_lines):
lower_limit = (
0 if not index else interval_lines[index - 1].inferior_limit
)
next_line = (
interval_lines[index] if index < len(interval_lines) else None
)
interval_range = self._get_values_for_range_intervals(
lower_limit, next_line.inferior_limit
)
if (
days_difference in interval_range
or days_difference == line.inferior_limit
):
ag_pb_data[acc_id][line] += residual
ag_pb_data[acc_id][prt_id][line] += residual
break
days_difference = abs((today - due_date).days)
for index, line in enumerate(interval_lines):
lower_limit = 0 if not index else interval_lines[index - 1].inferior_limit
next_line = interval_lines[index] if index < len(interval_lines) else None
interval_range = self._get_values_for_range_intervals(
lower_limit, next_line.inferior_limit
)
if (
days_difference in interval_range
or days_difference == line.inferior_limit
):
ag_pb_data[acc_id][line] += residual
ag_pb_data[acc_id][prt_id][line] += residual
break
return ag_pb_data
def _get_values_for_range_intervals(self, num1, num2):

View File

@@ -1,9 +1,9 @@
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models
from odoo import models
class AgedPartnerBalanceXslx(models.AbstractModel):
@@ -13,7 +13,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
def _get_report_name(self, report, data=False):
company_id = data.get("company_id", False)
report_name = _("Aged Partner Balance")
report_name = self.env._("Aged Partner Balance")
if company_id:
company = self.env["res.company"].browse(company_id)
suffix = f" - {company.name} - {company.currency_id.name}"
@@ -22,16 +22,16 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
def _get_report_columns_without_move_line_details(self, report, column_index):
report_columns = {
0: {"header": _("Partner"), "field": "name", "width": 70},
0: {"header": self.env._("Partner"), "field": "name", "width": 70},
1: {
"header": _("Residual"),
"header": self.env._("Residual"),
"field": "residual",
"field_footer_total": "residual",
"type": "amount",
"width": 14,
},
2: {
"header": _("Current"),
"header": self.env._("Current"),
"field": "current",
"field_footer_total": "current",
"field_footer_percent": "percent_current",
@@ -43,7 +43,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
report_columns.update(
{
3: {
"header": _("Age ≤ 30 d."),
"header": self.env._("Age ≤ 30 d."),
"field": "30_days",
"field_footer_total": "30_days",
"field_footer_percent": "percent_30_days",
@@ -51,7 +51,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
4: {
"header": _("Age ≤ 60 d."),
"header": self.env._("Age ≤ 60 d."),
"field": "60_days",
"field_footer_total": "60_days",
"field_footer_percent": "percent_60_days",
@@ -59,7 +59,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
5: {
"header": _("Age ≤ 90 d."),
"header": self.env._("Age ≤ 90 d."),
"field": "90_days",
"field_footer_total": "90_days",
"field_footer_percent": "percent_90_days",
@@ -67,7 +67,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
6: {
"header": _("Age ≤ 120 d."),
"header": self.env._("Age ≤ 120 d."),
"field": "120_days",
"field_footer_total": "120_days",
"field_footer_percent": "percent_120_days",
@@ -75,7 +75,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
7: {
"header": _("Older"),
"header": self.env._("Older"),
"field": "older",
"field_footer_total": "older",
"field_footer_percent": "percent_older",
@@ -98,15 +98,15 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
def _get_report_columns_with_move_line_details(self, report, column_index):
report_columns = {
0: {"header": _("Date"), "field": "date", "width": 11},
1: {"header": _("Entry"), "field": "entry", "width": 18},
2: {"header": _("Journal"), "field": "journal", "width": 8},
3: {"header": _("Account"), "field": "account", "width": 9},
4: {"header": _("Partner"), "field": "partner", "width": 25},
5: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
6: {"header": _("Due date"), "field": "due_date", "width": 11},
0: {"header": self.env._("Date"), "field": "date", "width": 11},
1: {"header": self.env._("Entry"), "field": "entry", "width": 18},
2: {"header": self.env._("Journal"), "field": "journal", "width": 8},
3: {"header": self.env._("Account"), "field": "account", "width": 9},
4: {"header": self.env._("Partner"), "field": "partner", "width": 25},
5: {"header": self.env._("Ref - Label"), "field": "ref_label", "width": 40},
6: {"header": self.env._("Due date"), "field": "due_date", "width": 11},
7: {
"header": _("Residual"),
"header": self.env._("Residual"),
"field": "residual",
"field_footer_total": "residual",
"field_final_balance": "residual",
@@ -114,7 +114,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
8: {
"header": _("Current"),
"header": self.env._("Current"),
"field": "current",
"field_footer_total": "current",
"field_footer_percent": "percent_current",
@@ -127,7 +127,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
report_columns.update(
{
9: {
"header": _("Age ≤ 30 d."),
"header": self.env._("Age ≤ 30 d."),
"field": "30_days",
"field_footer_total": "30_days",
"field_footer_percent": "percent_30_days",
@@ -136,7 +136,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
10: {
"header": _("Age ≤ 60 d."),
"header": self.env._("Age ≤ 60 d."),
"field": "60_days",
"field_footer_total": "60_days",
"field_footer_percent": "percent_60_days",
@@ -145,7 +145,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
11: {
"header": _("Age ≤ 90 d."),
"header": self.env._("Age ≤ 90 d."),
"field": "90_days",
"field_footer_total": "90_days",
"field_footer_percent": "percent_90_days",
@@ -154,7 +154,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
12: {
"header": _("Age ≤ 120 d."),
"header": self.env._("Age ≤ 120 d."),
"field": "120_days",
"field_footer_total": "120_days",
"field_footer_percent": "percent_120_days",
@@ -163,7 +163,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
"width": 14,
},
13: {
"header": _("Older"),
"header": self.env._("Older"),
"field": "older",
"field_footer_total": "older",
"field_footer_percent": "percent_older",
@@ -194,12 +194,12 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
def _get_report_filters(self, report):
return [
[_("Date at filter"), report.date_at.strftime("%d/%m/%Y")],
[self.env._("Date at filter"), report.date_at.strftime("%d/%m/%Y")],
[
_("Target moves filter"),
_("All posted entries")
self.env._("Target moves filter"),
self.env._("All posted entries")
if report.target_move == "posted"
else _("All entries"),
else self.env._("All entries"),
],
]
@@ -321,7 +321,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
for Aged Partner Balance
"""
name = None
label = _("Partner cumul aged balance")
label = self.env._("Partner cumul aged balance")
return super().write_ending_balance_from_dict(
my_object, name, label, report_data
)

View File

@@ -1,4 +1,4 @@
# ?? 2016 Julien Coux (Camptocamp)
# © 2016 Julien Coux (Camptocamp)
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2022 Tecnativa - V??ctor Mart??nez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -17,14 +17,18 @@ class GeneralLedgerReport(models.AbstractModel):
_inherit = "report.account_financial_report.abstract_report"
def _get_analytic_data(self, account_ids):
analytic_accounts = self.env["account.analytic.account"].browse(account_ids)
analytic_accounts = self.env["account.analytic.account"].search_fetch(
[("id", "in", account_ids)], ["name"]
)
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)
taxes = self.env["account.tax"].search_fetch(
[("id", "in", taxes_ids)], ["amount", "amount_type", "display_name"]
)
taxes_data = {}
for tax in taxes:
taxes_data.update(
@@ -61,7 +65,7 @@ class GeneralLedgerReport(models.AbstractModel):
def _get_acc_prt_accounts_ids(self, company_id, grouped_by):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
] + self._get_account_type_domain(grouped_by)
acc_prt_accounts = self.env["account.account"].search(accounts_domain)
return acc_prt_accounts.ids
@@ -70,7 +74,7 @@ class GeneralLedgerReport(models.AbstractModel):
self, account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=False
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", True),
]
if account_ids:
@@ -88,7 +92,7 @@ class GeneralLedgerReport(models.AbstractModel):
self, account_ids, company_id, date_from, fy_start_date, base_domain
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", False),
]
if account_ids:
@@ -118,7 +122,7 @@ class GeneralLedgerReport(models.AbstractModel):
self, account_ids, company_id, fy_start_date, base_domain
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", False),
]
if account_ids:
@@ -155,7 +159,13 @@ class GeneralLedgerReport(models.AbstractModel):
return pl_initial_balance
def _get_gl_initial_acc(
self, account_ids, company_id, date_from, fy_start_date, base_domain, grouped_by
self,
account_ids,
company_id,
date_from,
fy_start_date,
base_domain,
grouped_by,
):
initial_domain_bs = self._get_initial_balances_bs_ml_domain(
account_ids, company_id, date_from, base_domain, grouped_by
@@ -182,7 +192,7 @@ class GeneralLedgerReport(models.AbstractModel):
data[acc_id]["id"] = acc_id
if grouped_by:
data[acc_id][grouped_by] = False
method = "_prepare_gen_ld_data_group_%s" % grouped_by
method = f"_prepare_gen_ld_data_group_{grouped_by}"
if not hasattr(self, method):
return data
return getattr(self, method)(data, domain, grouped_by)
@@ -265,7 +275,7 @@ class GeneralLedgerReport(models.AbstractModel):
unaffected_earnings_account = False
base_domain = []
if company_id:
base_domain += [("company_id", "=", company_id)]
base_domain += [("company_id", "in", [company_id])]
if partner_ids:
base_domain += [("partner_id", "in", partner_ids)]
if only_posted_moves:
@@ -423,7 +433,9 @@ class GeneralLedgerReport(models.AbstractModel):
res.append({"id": item_id, "name": item_name})
elif move_line["tax_ids"]:
for tax_id in move_line["tax_ids"]:
tax_item = self.env["account.tax"].browse(tax_id)
tax_item = self.env["account.tax"].search_fetch(
[("id", "=", tax_id)], ["name"]
)
res.append({"id": tax_item.id, "name": tax_item.name})
else:
res.append({"id": 0, "name": "Missing Tax"})

View File

@@ -1,7 +1,7 @@
# Author: Damien Crier
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# Copyright 2022 Tecnativa - V??ctor Mart??nez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -203,7 +203,7 @@ class GeneralLedgerXslx(models.AbstractModel):
)
else:
analytic_distribution += (
"%s " % analytic_data[int(account_id)]["name"]
f"{analytic_data[int(account_id)]['name']} "
)
line.update(
{
@@ -313,7 +313,7 @@ class GeneralLedgerXslx(models.AbstractModel):
)
else:
analytic_distribution += (
"%s " % analytic_data[int(account_id)]["name"]
f"{analytic_data[int(account_id)]['name']} "
)
line.update(
{

View File

@@ -264,7 +264,9 @@ class JournalLedgerReport(models.AbstractModel):
journal_id = ml_data["journal_id"]
if journal_id not in journals_taxes_data.keys():
journals_taxes_data[journal_id] = {}
taxes = self.env["account.tax"].browse(tax_ids)
taxes = self.env["account.tax"].search_fetch(
[("id", "in", tax_ids)], ["name", "description"]
)
for tax in taxes:
if tax.id not in journals_taxes_data[journal_id]:
journals_taxes_data[journal_id][tax.id] = {

View File

@@ -1,7 +1,7 @@
# Author: Damien Crier
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models

View File

@@ -1,4 +1,4 @@
# ?? 2016 Julien Coux (Camptocamp)
# © 2016 Julien Coux (Camptocamp)
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

View File

@@ -1,6 +1,6 @@
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models

View File

@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="account_financial_report.html_container">
<link
href="/account_financial_report/static/src/css/report_html.css"
rel="stylesheet"
/>
<t t-call-assets="web.assets_backend" />
<t t-set="body_classname" t-value="'container'" />
<t t-call="web.report_layout">
<t t-out="0" />
@@ -12,17 +9,14 @@
</template>
<template id="account_financial_report.internal_layout">
<div class="article o_account_financial_reports_page">
<link
href="/account_financial_report/static/src/css/report.css"
rel="stylesheet"
/>
<t t-call-assets="web.assets_backend" />
<t t-out="0" />
</div>
<div class="footer">
<div class="row">
<div class="col-6 custom_footer">
<span
t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"
t-out="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"
/>
</div>
<div class="col-6 text-right custom_footer">

View File

@@ -1,5 +1,5 @@
# ?? 2016 Julien Coux (Camptocamp)
# ?? 2018 Forest and Biomass Romania SA
# © 2016 Julien Coux (Camptocamp)
# © 2018 Forest and Biomass Romania SA
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -24,7 +24,7 @@ class TrialBalanceReport(models.AbstractModel):
show_partner_details,
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", True),
]
if account_ids:
@@ -64,7 +64,7 @@ class TrialBalanceReport(models.AbstractModel):
fy_start_date,
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", False),
]
if account_ids:
@@ -142,7 +142,7 @@ class TrialBalanceReport(models.AbstractModel):
show_partner_details,
):
accounts_domain = [
("company_id", "=", company_id),
("company_ids", "in", [company_id]),
("include_initial_balance", "=", False),
]
if account_ids:
@@ -419,7 +419,7 @@ class TrialBalanceReport(models.AbstractModel):
fy_start_date,
grouped_by,
):
accounts_domain = [("company_id", "=", company_id)]
accounts_domain = [("company_ids", "in", [company_id])]
if account_ids:
accounts_domain += [("id", "in", account_ids)]
# If explicit list of accounts is provided,
@@ -697,7 +697,6 @@ class TrialBalanceReport(models.AbstractModel):
"code": group.code_prefix_start,
"name": group.name,
"parent_id": group.parent_id.id,
"parent_path": group.parent_path,
"complete_code": group.complete_code,
"account_ids": group.compute_account_ids.ids,
"type": "group_type",
@@ -751,7 +750,6 @@ class TrialBalanceReport(models.AbstractModel):
"code": group.code_prefix_start,
"name": group.name,
"parent_id": group.parent_id.id,
"parent_path": group.parent_path,
"type": "group_type",
"complete_code": group.complete_code,
"account_ids": group.compute_account_ids.ids,
@@ -804,7 +802,6 @@ class TrialBalanceReport(models.AbstractModel):
"code": group.code_prefix_start,
"name": group.name,
"parent_id": group.parent_id.id,
"parent_path": group.parent_path,
"type": "group_type",
"complete_code": group.complete_code,
"account_ids": group.compute_account_ids.ids,

View File

@@ -1,6 +1,6 @@
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

View File

@@ -97,7 +97,9 @@ class VATReport(models.AbstractModel):
return vat_data, tax_data
def _get_tax_group_data(self, tax_group_ids):
tax_groups = self.env["account.tax.group"].browse(tax_group_ids)
tax_groups = self.env["account.tax.group"].search_fetch(
[("id", "in", tax_group_ids)], ["name", "sequence"]
)
tax_group_data = {}
for tax_group in tax_groups:
tax_group_data.update(
@@ -135,7 +137,7 @@ class VATReport(models.AbstractModel):
vat_report[tax_group_id]["tax"] += tax_move_line["tax"]
vat_report[tax_group_id][tax_id]["net"] += tax_move_line["net"]
vat_report[tax_group_id][tax_id]["tax"] += tax_move_line["tax"]
tax_group_data = self._get_tax_group_data(vat_report.keys())
tax_group_data = self._get_tax_group_data(list(vat_report.keys()))
vat_report_list = []
for tax_group_id in vat_report.keys():
vat_report[tax_group_id]["name"] = tax_group_data[tax_group_id]["name"]
@@ -151,7 +153,9 @@ class VATReport(models.AbstractModel):
return vat_report_list
def _get_tags_data(self, tags_ids):
tags = self.env["account.account.tag"].browse(tags_ids)
tags = self.env["account.account.tag"].search_fetch(
[("id", "in", tags_ids)], ["name"]
)
tags_data = {}
for tag in tags:
tags_data.update({tag.id: {"code": "", "name": tag.name}})
@@ -183,7 +187,7 @@ class VATReport(models.AbstractModel):
vat_report[tag_id][tax_id]["tax"] += tax_move_line["tax"]
vat_report[tag_id]["net"] += tax_move_line["net"]
vat_report[tag_id]["tax"] += tax_move_line["tax"]
tags_data = self._get_tags_data(vat_report.keys())
tags_data = self._get_tags_data(list(vat_report.keys()))
vat_report_list = []
for tag_id in vat_report.keys():
vat_report[tag_id]["name"] = tags_data[tag_id]["name"]

View File

@@ -1,5 +1,5 @@
# Copyright 2018 Forest and Biomass Romania
# Copyright 2021 Tecnativa - Jo??o Marques
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models