commit
c322c6db52
|
@ -50,14 +50,24 @@
|
||||||
</t>
|
</t>
|
||||||
<t t-if="hierarchy_on == 'computed'">
|
<t t-if="hierarchy_on == 'computed'">
|
||||||
<t t-if="balance['type'] == 'group_type'">
|
<t t-if="balance['type'] == 'group_type'">
|
||||||
|
<t
|
||||||
|
t-if="not limit_hierarchy_level or (
|
||||||
|
show_hierarchy_level >= balance['level'] and (
|
||||||
|
not hide_parent_hierarchy_level or show_hierarchy_level == balance['level']))"
|
||||||
|
>
|
||||||
|
<t
|
||||||
|
t-if="not limit_hierarchy_level or show_hierarchy_level > balance['level']"
|
||||||
|
>
|
||||||
<t
|
<t
|
||||||
t-set="style"
|
t-set="style"
|
||||||
t-value="style + 'font-weight: bold; color: blue;'"
|
t-value="style + 'font-weight: bold; color: blue;'"
|
||||||
/>
|
/>
|
||||||
|
</t>
|
||||||
<t
|
<t
|
||||||
t-call="account_financial_report.report_trial_balance_line"
|
t-call="account_financial_report.report_trial_balance_line"
|
||||||
/>
|
/>
|
||||||
</t>
|
</t>
|
||||||
|
</t>
|
||||||
<t t-if="balance['type'] == 'account_type'">
|
<t t-if="balance['type'] == 'account_type'">
|
||||||
<t
|
<t
|
||||||
t-call="account_financial_report.report_trial_balance_line"
|
t-call="account_financial_report.report_trial_balance_line"
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
# © 2016 Julien Coux (Camptocamp)
|
# © 2016 Julien Coux (Camptocamp)
|
||||||
# © 2018 Forest and Biomass Romania SA
|
# © 2018 Forest and Biomass Romania SA
|
||||||
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
|
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||||
|
# Copyright 2021 Tecnativa - Carlos Dauden
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from odoo import _, api, models
|
||||||
from odoo import api, models
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class TrialBalanceReport(models.AbstractModel):
|
class TrialBalanceReport(models.AbstractModel):
|
||||||
|
@ -596,53 +597,119 @@ class TrialBalanceReport(models.AbstractModel):
|
||||||
)
|
)
|
||||||
return groups_data
|
return groups_data
|
||||||
|
|
||||||
def _get_computed_groups_data(self, accounts_data, total_amount, foreign_currency):
|
@api.model
|
||||||
groups = self.env["account.group"].search([("id", "!=", False)])
|
def _get_computed_account_groups(self, account_code, data, groups):
|
||||||
groups_data = {}
|
show_hierarchy_level = data["show_hierarchy_level"]
|
||||||
for group in groups:
|
limit_hierarchy_level = data["limit_hierarchy_level"]
|
||||||
len_group_code = len(group.code_prefix)
|
account_groups = []
|
||||||
groups_data.update(
|
if limit_hierarchy_level:
|
||||||
{
|
limit_level = show_hierarchy_level
|
||||||
group.id: {
|
else:
|
||||||
"id": group.id,
|
limit_level = len(account_code)
|
||||||
"code": group.code_prefix,
|
for i in range(limit_level + 1):
|
||||||
"name": group.name,
|
group_code = account_code[:i]
|
||||||
"parent_id": group.parent_id.id,
|
group = groups.filtered(lambda g: g.code_prefix == group_code)[:1]
|
||||||
"parent_path": group.parent_path,
|
# Only append existing groups if not limit_hierarchy_level
|
||||||
|
if limit_hierarchy_level or group:
|
||||||
|
account_groups.append((group_code, group))
|
||||||
|
return account_groups
|
||||||
|
|
||||||
|
def _get_computed_groups_data(
|
||||||
|
self, accounts_data, total_amount, foreign_currency, data
|
||||||
|
):
|
||||||
|
show_hierarchy_level = data["show_hierarchy_level"]
|
||||||
|
hide_parent_hierarchy_level = data["hide_parent_hierarchy_level"]
|
||||||
|
groups = self.env["account.group"].search([])
|
||||||
|
groups_data = {
|
||||||
|
"": {
|
||||||
|
"id": False,
|
||||||
|
"code": "",
|
||||||
|
"name": "Total",
|
||||||
|
"parent_id": False,
|
||||||
|
"parent_path": "",
|
||||||
|
"level": show_hierarchy_level if hide_parent_hierarchy_level else 0,
|
||||||
"type": "group_type",
|
"type": "group_type",
|
||||||
"complete_code": group.complete_code,
|
"complete_code": "",
|
||||||
"account_ids": group.compute_account_ids.ids,
|
"account_ids": [],
|
||||||
"initial_balance": 0.0,
|
"initial_balance": 0.0,
|
||||||
"credit": 0.0,
|
|
||||||
"debit": 0.0,
|
"debit": 0.0,
|
||||||
|
"credit": 0.0,
|
||||||
"balance": 0.0,
|
"balance": 0.0,
|
||||||
"ending_balance": 0.0,
|
"ending_balance": 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
if foreign_currency:
|
if foreign_currency:
|
||||||
groups_data[group.id]["initial_currency_balance"] = 0.0
|
groups_data[""].update(
|
||||||
groups_data[group.id]["ending_currency_balance"] = 0.0
|
{"initial_currency_balance": 0.0, "ending_currency_balance": 0.0}
|
||||||
|
)
|
||||||
for account in accounts_data.values():
|
for account in accounts_data.values():
|
||||||
if group.code_prefix == account["code"][:len_group_code]:
|
previous_group = False
|
||||||
|
for group_code, group in self._get_computed_account_groups(
|
||||||
|
account["code"], data, groups
|
||||||
|
):
|
||||||
|
if group_code and not group and not previous_group:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Code %s can not be related with any account group")
|
||||||
|
% group_code
|
||||||
|
)
|
||||||
acc_id = account["id"]
|
acc_id = account["id"]
|
||||||
group_id = group.id
|
if group_code not in groups_data:
|
||||||
groups_data[group_id]["initial_balance"] += total_amount[acc_id][
|
len_group = len(group_code)
|
||||||
|
groups_data[group_code] = {
|
||||||
|
"id": group.id if group else previous_group.id,
|
||||||
|
"code": group_code,
|
||||||
|
"name": group.name
|
||||||
|
if group
|
||||||
|
else "{} ({})".format(previous_group.name, group_code),
|
||||||
|
"parent_id": group.parent_id.id if group else previous_group.id,
|
||||||
|
"parent_path": group.parent_path
|
||||||
|
if group
|
||||||
|
else previous_group.parent_path,
|
||||||
|
"level": len_group,
|
||||||
|
"type": "group_type",
|
||||||
|
"complete_code": "/".join(
|
||||||
|
[group_code[:i] for i in range(1, len_group)]
|
||||||
|
),
|
||||||
|
"account_ids": [account["id"]],
|
||||||
|
"initial_balance": total_amount[acc_id]["initial_balance"],
|
||||||
|
"debit": total_amount[acc_id]["debit"],
|
||||||
|
"credit": total_amount[acc_id]["credit"],
|
||||||
|
"balance": total_amount[acc_id]["balance"],
|
||||||
|
"ending_balance": total_amount[acc_id]["ending_balance"],
|
||||||
|
}
|
||||||
|
if foreign_currency:
|
||||||
|
groups_data[group_code].update(
|
||||||
|
{
|
||||||
|
"initial_currency_balance": total_amount[acc_id][
|
||||||
|
"initial_currency_balance"
|
||||||
|
],
|
||||||
|
"ending_currency_balance": total_amount[acc_id][
|
||||||
|
"ending_currency_balance"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
groups_data[group_code]["account_ids"].append(acc_id)
|
||||||
|
groups_data[group_code]["initial_balance"] += total_amount[acc_id][
|
||||||
"initial_balance"
|
"initial_balance"
|
||||||
]
|
]
|
||||||
groups_data[group_id]["debit"] += total_amount[acc_id]["debit"]
|
groups_data[group_code]["debit"] += total_amount[acc_id]["debit"]
|
||||||
groups_data[group_id]["credit"] += total_amount[acc_id]["credit"]
|
groups_data[group_code]["credit"] += total_amount[acc_id]["credit"]
|
||||||
groups_data[group_id]["balance"] += total_amount[acc_id]["balance"]
|
groups_data[group_code]["balance"] += total_amount[acc_id][
|
||||||
groups_data[group_id]["ending_balance"] += total_amount[acc_id][
|
"balance"
|
||||||
|
]
|
||||||
|
groups_data[group_code]["ending_balance"] += total_amount[acc_id][
|
||||||
"ending_balance"
|
"ending_balance"
|
||||||
]
|
]
|
||||||
if foreign_currency:
|
if foreign_currency:
|
||||||
groups_data[group_id][
|
groups_data[group_code][
|
||||||
"initial_currency_balance"
|
"initial_currency_balance"
|
||||||
] += total_amount[acc_id]["initial_currency_balance"]
|
] += total_amount[acc_id]["initial_currency_balance"]
|
||||||
groups_data[group_id][
|
groups_data[group_code][
|
||||||
"ending_currency_balance"
|
"ending_currency_balance"
|
||||||
] += total_amount[acc_id]["ending_currency_balance"]
|
] += total_amount[acc_id]["ending_currency_balance"]
|
||||||
|
if group:
|
||||||
|
previous_group = group
|
||||||
return groups_data
|
return groups_data
|
||||||
|
|
||||||
def _get_report_values(self, docids, data):
|
def _get_report_values(self, docids, data):
|
||||||
|
@ -657,6 +724,7 @@ class TrialBalanceReport(models.AbstractModel):
|
||||||
date_from = data["date_from"]
|
date_from = data["date_from"]
|
||||||
hide_account_at_0 = data["hide_account_at_0"]
|
hide_account_at_0 = data["hide_account_at_0"]
|
||||||
hierarchy_on = data["hierarchy_on"]
|
hierarchy_on = data["hierarchy_on"]
|
||||||
|
limit_hierarchy_level = data["limit_hierarchy_level"]
|
||||||
show_hierarchy_level = data["show_hierarchy_level"]
|
show_hierarchy_level = data["show_hierarchy_level"]
|
||||||
foreign_currency = data["foreign_currency"]
|
foreign_currency = data["foreign_currency"]
|
||||||
only_posted_moves = data["only_posted_moves"]
|
only_posted_moves = data["only_posted_moves"]
|
||||||
|
@ -712,9 +780,10 @@ class TrialBalanceReport(models.AbstractModel):
|
||||||
trial["level"] = counter
|
trial["level"] = counter
|
||||||
if hierarchy_on == "computed":
|
if hierarchy_on == "computed":
|
||||||
groups_data = self._get_computed_groups_data(
|
groups_data = self._get_computed_groups_data(
|
||||||
accounts_data, total_amount, foreign_currency
|
accounts_data, total_amount, foreign_currency, data
|
||||||
)
|
)
|
||||||
trial_balance = list(groups_data.values())
|
trial_balance = list(groups_data.values())
|
||||||
|
if not limit_hierarchy_level:
|
||||||
trial_balance += list(accounts_data.values())
|
trial_balance += list(accounts_data.values())
|
||||||
trial_balance = sorted(trial_balance, key=lambda k: k["code"])
|
trial_balance = sorted(trial_balance, key=lambda k: k["code"])
|
||||||
if hierarchy_on == "none":
|
if hierarchy_on == "none":
|
||||||
|
|
|
@ -186,6 +186,7 @@ class TrialBalanceXslx(models.AbstractModel):
|
||||||
show_hierarchy_level = res_data["show_hierarchy_level"]
|
show_hierarchy_level = res_data["show_hierarchy_level"]
|
||||||
foreign_currency = res_data["foreign_currency"]
|
foreign_currency = res_data["foreign_currency"]
|
||||||
limit_hierarchy_level = res_data["limit_hierarchy_level"]
|
limit_hierarchy_level = res_data["limit_hierarchy_level"]
|
||||||
|
hide_parent_hierarchy_level = data["hide_parent_hierarchy_level"]
|
||||||
if not show_partner_details:
|
if not show_partner_details:
|
||||||
# Display array header for account lines
|
# Display array header for account lines
|
||||||
self.write_array_header()
|
self.write_array_header()
|
||||||
|
@ -201,9 +202,11 @@ class TrialBalanceXslx(models.AbstractModel):
|
||||||
else:
|
else:
|
||||||
self.write_line_from_dict(balance)
|
self.write_line_from_dict(balance)
|
||||||
elif hierarchy_on == "computed":
|
elif hierarchy_on == "computed":
|
||||||
if balance["type"] == "account_type":
|
|
||||||
if limit_hierarchy_level:
|
if limit_hierarchy_level:
|
||||||
if show_hierarchy_level > balance["level"]:
|
if show_hierarchy_level == balance["level"] or (
|
||||||
|
not hide_parent_hierarchy_level
|
||||||
|
and show_hierarchy_level > balance["level"]
|
||||||
|
):
|
||||||
# Display account lines
|
# Display account lines
|
||||||
self.write_line_from_dict(balance)
|
self.write_line_from_dict(balance)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="limit_hierarchy_level"
|
name="limit_hierarchy_level"
|
||||||
attrs="{'invisible':['|', ('hierarchy_on','in',['none', 'computed']),('show_partner_details','=',True)]}"
|
attrs="{'invisible':['|', ('hierarchy_on','=','none'),('show_partner_details','=',True)]}"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="show_hierarchy_level"
|
name="show_hierarchy_level"
|
||||||
|
|
Loading…
Reference in New Issue