Skip to content

Commit 1cb95fa

Browse files
committed
Merge PR #1254 into 16.0
Signed-off-by pedrobaeza
2 parents 9e399c5 + 0a2b273 commit 1cb95fa

File tree

3 files changed

+79
-22
lines changed

3 files changed

+79
-22
lines changed

account_financial_report/report/general_ledger.py

+56
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ def _get_centralized_ml(self, account, date_to, grouped_by):
764764
list_centralized_ml += list(centralized_ml[jnl_id].values())
765765
return list_centralized_ml
766766

767+
# flake8: noqa: C901
767768
def _get_report_values(self, docids, data):
768769
wizard_id = data["wizard_id"]
769770
company = self.env["res.company"].browse(data["company_id"])
@@ -838,6 +839,61 @@ def _get_report_values(self, docids, data):
838839
account[grouped_by] = False
839840
del account["list_grouped"]
840841
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
842+
# Set the bal_curr of the initial balance to 0 if it does not correspond
843+
# (reducing the corresponding of the bal_curr of the initial balance).
844+
for gl_item in general_ledger:
845+
if not foreign_currency:
846+
continue
847+
if (
848+
not gl_item["currency_id"]
849+
or gl_item["currency_id"] != company.currency_id
850+
):
851+
gl_item["fin_bal"]["bal_curr"] -= gl_item["init_bal"]["bal_curr"]
852+
gl_item["init_bal"]["bal_curr"] = 0
853+
if "list_grouped" in gl_item:
854+
for lg_item in gl_item["list_grouped"]:
855+
lg_item["fin_bal"]["bal_curr"] -= lg_item["init_bal"][
856+
"bal_curr"
857+
]
858+
lg_item["init_bal"]["bal_curr"] = 0
859+
# Set the fin_bal_currency_id value if the account does not have it set
860+
# and there are move lines in a currency different from that of
861+
# the company (USD for example).
862+
for gl_item in general_ledger:
863+
fin_bal_currency_ids = []
864+
fin_bal_currency_id = gl_item["currency_id"]
865+
if gl_item["currency_id"] or not foreign_currency:
866+
continue
867+
gl_item["fin_bal"]["bal_curr"] = gl_item["init_bal"]["bal_curr"]
868+
if "move_lines" in gl_item:
869+
for ml in gl_item["move_lines"]:
870+
ml_currency_id = (
871+
ml["currency_id"][0] if ml["currency_id"] else False
872+
)
873+
if ml_currency_id and ml_currency_id != company.currency_id.id:
874+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
875+
if ml_currency_id not in fin_bal_currency_ids:
876+
fin_bal_currency_ids.append(ml_currency_id)
877+
elif "list_grouped" in gl_item:
878+
fin_bal_currency_ids = []
879+
for lg_item in gl_item["list_grouped"]:
880+
lg_item["fin_bal"]["bal_curr"] = lg_item["init_bal"]["bal_curr"]
881+
for ml in lg_item["move_lines"]:
882+
ml_currency_id = (
883+
ml["currency_id"][0] if ml["currency_id"] else False
884+
)
885+
if ml_currency_id and ml_currency_id != company.currency_id.id:
886+
lg_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
887+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
888+
if ml_currency_id not in fin_bal_currency_ids:
889+
fin_bal_currency_ids.append(ml_currency_id)
890+
# If there is only 1 currency, we set that one as fin_bal_currency_id
891+
# The use of different move lines with different currencies (EUR + GBP)
892+
# will be excluded. We use a different field to avoid showing the initial
893+
# balance and/or distorting data.
894+
if not gl_item["currency_id"] and len(fin_bal_currency_ids) == 1:
895+
fin_bal_currency_id = fin_bal_currency_ids[0]
896+
gl_item["fin_bal_currency_id"] = fin_bal_currency_id
841897
return {
842898
"doc_ids": [wizard_id],
843899
"doc_model": "general.ledger.report.wizard",

account_financial_report/report/general_ledger_xlsx.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,11 @@ def _generate_report_content(self, workbook, report, data, report_data):
357357
"final_balance": account["fin_bal"]["balance"],
358358
}
359359
)
360-
if foreign_currency and account["currency_id"]:
360+
if foreign_currency and account["fin_bal_currency_id"]:
361361
account.update(
362362
{
363-
"final_bal_curr": account["fin_bal"]["bal_curr"],
363+
"final_bal_curr": total_bal_curr,
364+
"currency_id": account["fin_bal_currency_id"],
364365
}
365366
)
366367
self.write_ending_balance_from_dict(account, report_data)

account_financial_report/report/templates/general_ledger.xml

+20-20
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<div class="row">
2525
<h4
2626
class="mt0"
27-
t-esc="title or 'Odoo Report'"
27+
t-out="title or 'Odoo Report'"
2828
style="text-align: center;"
2929
/>
3030
</div>
@@ -35,9 +35,9 @@
3535
<!-- Display account header -->
3636
<div class="act_as_table list_table" style="margin-top: 10px;" />
3737
<div class="act_as_caption account_title" style="width: 100%">
38-
<span t-esc="account['code']" />
38+
<span t-out="account['code']" />
3939
-
40-
<span t-esc="account['name']" />
40+
<span t-out="account['name']" />
4141
</div>
4242
<t t-if="'list_grouped' not in account">
4343
<!-- Display account move lines without partner regroup -->
@@ -62,7 +62,7 @@
6262
<div class="page_break">
6363
<!-- Display partner header -->
6464
<div class="act_as_caption account_title">
65-
<span t-esc="group_item['name']" />
65+
<span t-out="group_item['name']" />
6666
</div>
6767
<!-- Display partner move lines -->
6868
<t
@@ -113,9 +113,9 @@
113113
<div class="act_as_row">
114114
<div class="act_as_cell">
115115
From:
116-
<span t-esc="date_from" />
116+
<span t-out="date_from" />
117117
To:
118-
<span t-esc="date_to" />
118+
<span t-out="date_to" />
119119
</div>
120120
<div class="act_as_cell">
121121
<t t-if="only_posted_moves">All posted entries</t>
@@ -381,7 +381,7 @@
381381
view-type="form"
382382
>
383383
<t
384-
t-esc="line['date']"
384+
t-out="line['date']"
385385
t-options="{'widget': 'date'}"
386386
/>
387387
</span>
@@ -390,7 +390,7 @@
390390
<span>
391391
<!--## We don't use t-field because it throws an error on click -->
392392
<t
393-
t-esc="line['date']"
393+
t-out="line['date']"
394394
t-options="{'widget': 'date'}"
395395
/>
396396
</span>
@@ -435,12 +435,12 @@
435435
<t t-if="taxes_data and line['tax_ids']">
436436
<t t-foreach="line['tax_ids']" t-as="tax_id">
437437
<span
438-
t-esc="o._get_atr_from_dict(tax_id, taxes_data, 'tax_name')"
438+
t-out="o._get_atr_from_dict(tax_id, taxes_data, 'tax_name')"
439439
/>
440440
</t>
441441
</t>
442442
<t t-if="line['tax_line_id']">
443-
<span t-esc="line['tax_line_id'][1]" />
443+
<span t-out="line['tax_line_id'][1]" />
444444
</t>
445445
</div>
446446
<!--## partner-->
@@ -486,13 +486,13 @@
486486
view-type="form"
487487
>
488488
<t
489-
t-esc="o._get_atr_from_dict(int(analytic_id), analytic_data, 'name')"
489+
t-out="o._get_atr_from_dict(int(analytic_id), analytic_data, 'name')"
490490
/>
491491
<t
492492
t-if="int(line['analytic_distribution'][analytic_id]) &lt; 100"
493493
>
494494
<t
495-
t-esc="int(line['analytic_distribution'][analytic_id])"
495+
t-out="int(line['analytic_distribution'][analytic_id])"
496496
/>%
497497
</t>
498498
</span>
@@ -506,7 +506,7 @@
506506
<t t-if="line['tag_ids']">
507507
<t t-foreach="line['tag_ids']" t-as="tag_id">
508508
<span
509-
t-esc="o._get_atr_from_dict(tag_id, tags_data, 'name')"
509+
t-out="o._get_atr_from_dict(tag_id, tags_data, 'name')"
510510
/>
511511
</t>
512512
</t>
@@ -645,9 +645,9 @@
645645
<!--## date-->
646646
<t t-if='type == "account_type"'>
647647
<div class="act_as_cell first_column" style="width: 41.32%;">
648-
<span t-esc="account['code']" />
648+
<span t-out="account['code']" />
649649
-
650-
<span t-esc="account['name']" />
650+
<span t-out="account['name']" />
651651
</div>
652652
<div class="act_as_cell right" style="width: 16.9%;">Ending balance
653653
</div>
@@ -672,21 +672,21 @@
672672
<!--## debit-->
673673
<div class="act_as_cell amount" style="width: 8.02%;">
674674
<span
675-
t-esc="account_or_group_item_object['fin_bal']['debit']"
675+
t-out="account_or_group_item_object['fin_bal']['debit']"
676676
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
677677
/>
678678
</div>
679679
<!--## credit-->
680680
<div class="act_as_cell amount" style="width: 8.02%;">
681681
<span
682-
t-esc="account_or_group_item_object['fin_bal']['credit']"
682+
t-out="account_or_group_item_object['fin_bal']['credit']"
683683
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
684684
/>
685685
</div>
686686
<!--## balance cumulated-->
687687
<div class="act_as_cell amount" style="width: 8.02%;">
688688
<span
689-
t-esc="account_or_group_item_object['fin_bal']['balance']"
689+
t-out="account_or_group_item_object['fin_bal']['balance']"
690690
t-options="{'widget': 'monetary', 'display_currency': company_currency}"
691691
/>
692692
</div>
@@ -702,10 +702,10 @@
702702
/>
703703
<t t-set="misc_grouped_domain" t-value="[]" t-else="" />
704704
<t t-if="foreign_currency">
705-
<t t-if="account['currency_id']">
705+
<t t-if="account['fin_bal_currency_id']">
706706
<t
707707
t-set="account_currency"
708-
t-value="currency_model.browse(account['currency_id'])"
708+
t-value="currency_model.browse(account['fin_bal_currency_id'])"
709709
/>
710710
<div class="act_as_cell amount" style="width: 3.63%;">
711711
<t t-if="type == 'account_type'">

0 commit comments

Comments
 (0)