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: Add Amount cur. to General Ledger totals if the account has not set currency #1254

Merged
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
56 changes: 56 additions & 0 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@
list_centralized_ml += list(centralized_ml[jnl_id].values())
return list_centralized_ml

# flake8: noqa: C901
def _get_report_values(self, docids, data):
wizard_id = data["wizard_id"]
company = self.env["res.company"].browse(data["company_id"])
Expand Down Expand Up @@ -838,6 +839,61 @@
account[grouped_by] = False
del account["list_grouped"]
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
# Set the bal_curr of the initial balance to 0 if it does not correspond
# (reducing the corresponding of the bal_curr of the initial balance).
for gl_item in general_ledger:
if not foreign_currency:
continue

Check warning on line 846 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L846

Added line #L846 was not covered by tests
if (
not gl_item["currency_id"]
or gl_item["currency_id"] != company.currency_id
):
gl_item["fin_bal"]["bal_curr"] -= gl_item["init_bal"]["bal_curr"]
gl_item["init_bal"]["bal_curr"] = 0
if "list_grouped" in gl_item:
for lg_item in gl_item["list_grouped"]:
lg_item["fin_bal"]["bal_curr"] -= lg_item["init_bal"][
"bal_curr"
]
lg_item["init_bal"]["bal_curr"] = 0
# Set the fin_bal_currency_id value if the account does not have it set
# and there are move lines in a currency different from that of
# the company (USD for example).
for gl_item in general_ledger:
fin_bal_currency_ids = []
fin_bal_currency_id = gl_item["currency_id"]
if gl_item["currency_id"] or not foreign_currency:
continue

Check warning on line 866 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L866

Added line #L866 was not covered by tests
gl_item["fin_bal"]["bal_curr"] = gl_item["init_bal"]["bal_curr"]
if "move_lines" in gl_item:
for ml in gl_item["move_lines"]:
ml_currency_id = (
ml["currency_id"][0] if ml["currency_id"] else False
)
if ml_currency_id and ml_currency_id != company.currency_id.id:
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]

Check warning on line 874 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L874

Added line #L874 was not covered by tests
if ml_currency_id not in fin_bal_currency_ids:
fin_bal_currency_ids.append(ml_currency_id)

Check warning on line 876 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L876

Added line #L876 was not covered by tests
elif "list_grouped" in gl_item:
fin_bal_currency_ids = []
for lg_item in gl_item["list_grouped"]:
lg_item["fin_bal"]["bal_curr"] = lg_item["init_bal"]["bal_curr"]
for ml in lg_item["move_lines"]:
ml_currency_id = (
ml["currency_id"][0] if ml["currency_id"] else False
)
if ml_currency_id and ml_currency_id != company.currency_id.id:
lg_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]

Check warning on line 887 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L886-L887

Added lines #L886 - L887 were not covered by tests
if ml_currency_id not in fin_bal_currency_ids:
fin_bal_currency_ids.append(ml_currency_id)

Check warning on line 889 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L889

Added line #L889 was not covered by tests
# If there is only 1 currency, we set that one as fin_bal_currency_id
# The use of different move lines with different currencies (EUR + GBP)
# will be excluded. We use a different field to avoid showing the initial
# balance and/or distorting data.
if not gl_item["currency_id"] and len(fin_bal_currency_ids) == 1:
fin_bal_currency_id = fin_bal_currency_ids[0]

Check warning on line 895 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L895

Added line #L895 was not covered by tests
gl_item["fin_bal_currency_id"] = fin_bal_currency_id
return {
"doc_ids": [wizard_id],
"doc_model": "general.ledger.report.wizard",
Expand Down
5 changes: 3 additions & 2 deletions account_financial_report/report/general_ledger_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,11 @@ def _generate_report_content(self, workbook, report, data, report_data):
"final_balance": account["fin_bal"]["balance"],
}
)
if foreign_currency and account["currency_id"]:
if foreign_currency and account["fin_bal_currency_id"]:
account.update(
{
"final_bal_curr": account["fin_bal"]["bal_curr"],
"final_bal_curr": total_bal_curr,
"currency_id": account["fin_bal_currency_id"],
}
)
self.write_ending_balance_from_dict(account, report_data)
Expand Down
40 changes: 20 additions & 20 deletions account_financial_report/report/templates/general_ledger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="row">
<h4
class="mt0"
t-esc="title or 'Odoo Report'"
t-out="title or 'Odoo Report'"
style="text-align: center;"
/>
</div>
Expand All @@ -35,9 +35,9 @@
<!-- Display account header -->
<div class="act_as_table list_table" style="margin-top: 10px;" />
<div class="act_as_caption account_title" style="width: 100%">
<span t-esc="account['code']" />
<span t-out="account['code']" />
-
<span t-esc="account['name']" />
<span t-out="account['name']" />
</div>
<t t-if="'list_grouped' not in account">
<!-- Display account move lines without partner regroup -->
Expand All @@ -62,7 +62,7 @@
<div class="page_break">
<!-- Display partner header -->
<div class="act_as_caption account_title">
<span t-esc="group_item['name']" />
<span t-out="group_item['name']" />
</div>
<!-- Display partner move lines -->
<t
Expand Down Expand Up @@ -113,9 +113,9 @@
<div class="act_as_row">
<div class="act_as_cell">
From:
<span t-esc="date_from" />
<span t-out="date_from" />
To:
<span t-esc="date_to" />
<span t-out="date_to" />
</div>
<div class="act_as_cell">
<t t-if="only_posted_moves">All posted entries</t>
Expand Down Expand Up @@ -381,7 +381,7 @@
view-type="form"
>
<t
t-esc="line['date']"
t-out="line['date']"
t-options="{'widget': 'date'}"
/>
</span>
Expand All @@ -390,7 +390,7 @@
<span>
<!--## We don't use t-field because it throws an error on click -->
<t
t-esc="line['date']"
t-out="line['date']"
t-options="{'widget': 'date'}"
/>
</span>
Expand Down Expand Up @@ -435,12 +435,12 @@
<t t-if="taxes_data and line['tax_ids']">
<t t-foreach="line['tax_ids']" t-as="tax_id">
<span
t-esc="o._get_atr_from_dict(tax_id, taxes_data, 'tax_name')"
t-out="o._get_atr_from_dict(tax_id, taxes_data, 'tax_name')"
/>
</t>
</t>
<t t-if="line['tax_line_id']">
<span t-esc="line['tax_line_id'][1]" />
<span t-out="line['tax_line_id'][1]" />
</t>
</div>
<!--## partner-->
Expand Down Expand Up @@ -486,13 +486,13 @@
view-type="form"
>
<t
t-esc="o._get_atr_from_dict(int(analytic_id), analytic_data, 'name')"
t-out="o._get_atr_from_dict(int(analytic_id), analytic_data, 'name')"
/>
<t
t-if="int(line['analytic_distribution'][analytic_id]) &lt; 100"
>
<t
t-esc="int(line['analytic_distribution'][analytic_id])"
t-out="int(line['analytic_distribution'][analytic_id])"
/>%
</t>
</span>
Expand All @@ -506,7 +506,7 @@
<t t-if="line['tag_ids']">
<t t-foreach="line['tag_ids']" t-as="tag_id">
<span
t-esc="o._get_atr_from_dict(tag_id, tags_data, 'name')"
t-out="o._get_atr_from_dict(tag_id, tags_data, 'name')"
/>
</t>
</t>
Expand Down Expand Up @@ -645,9 +645,9 @@
<!--## date-->
<t t-if='type == "account_type"'>
<div class="act_as_cell first_column" style="width: 41.32%;">
<span t-esc="account['code']" />
<span t-out="account['code']" />
-
<span t-esc="account['name']" />
<span t-out="account['name']" />
</div>
<div class="act_as_cell right" style="width: 16.9%;">Ending balance
</div>
Expand All @@ -672,21 +672,21 @@
<!--## debit-->
<div class="act_as_cell amount" style="width: 8.02%;">
<span
t-esc="account_or_group_item_object['fin_bal']['debit']"
t-out="account_or_group_item_object['fin_bal']['debit']"
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
/>
</div>
<!--## credit-->
<div class="act_as_cell amount" style="width: 8.02%;">
<span
t-esc="account_or_group_item_object['fin_bal']['credit']"
t-out="account_or_group_item_object['fin_bal']['credit']"
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
/>
</div>
<!--## balance cumulated-->
<div class="act_as_cell amount" style="width: 8.02%;">
<span
t-esc="account_or_group_item_object['fin_bal']['balance']"
t-out="account_or_group_item_object['fin_bal']['balance']"
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
/>
</div>
Expand All @@ -702,10 +702,10 @@
/>
<t t-set="misc_grouped_domain" t-value="[]" t-else="" />
<t t-if="foreign_currency">
<t t-if="account['currency_id']">
<t t-if="account['fin_bal_currency_id']">
<t
t-set="account_currency"
t-value="currency_model.browse(account['currency_id'])"
t-value="currency_model.browse(account['fin_bal_currency_id'])"
/>
<div class="act_as_cell amount" style="width: 3.63%;">
<t t-if="type == 'account_type'">
Expand Down
Loading