Skip to content

Commit fb90b3d

Browse files
committed
Merge PR #1236 into 15.0
Signed-off-by pedrobaeza
2 parents 5d7e080 + 32ca933 commit fb90b3d

File tree

3 files changed

+107
-52
lines changed

3 files changed

+107
-52
lines changed

account_financial_report/report/general_ledger.py

+54
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ def _get_centralized_ml(self, account, date_to, grouped_by):
774774
list_centralized_ml += list(centralized_ml[jnl_id].values())
775775
return list_centralized_ml
776776

777+
# flake8: noqa: C901
777778
def _get_report_values(self, docids, data):
778779
wizard_id = data["wizard_id"]
779780
wizard = self.env["general.ledger.report.wizard"].browse(wizard_id)
@@ -852,6 +853,59 @@ def _get_report_values(self, docids, data):
852853
account[grouped_by] = False
853854
del account["list_grouped"]
854855
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
856+
# Set the bal_curr of the initial balance to 0 if it does not correspond
857+
# (reducing the corresponding of the bal_curr of the initial balance).
858+
for gl_item in general_ledger:
859+
if (
860+
not gl_item["currency_id"]
861+
or gl_item["currency_id"] != company.currency_id
862+
):
863+
gl_item["fin_bal"]["bal_curr"] -= gl_item["init_bal"]["bal_curr"]
864+
gl_item["init_bal"]["bal_curr"] = 0
865+
if "list_grouped" in gl_item:
866+
for lg_item in gl_item["list_grouped"]:
867+
lg_item["fin_bal"]["bal_curr"] -= lg_item["init_bal"][
868+
"bal_curr"
869+
]
870+
lg_item["init_bal"]["bal_curr"] = 0
871+
# Set the fin_bal_currency_id value if the account does not have it set
872+
# and there are move lines in a currency different from that of
873+
# the company (USD for example).
874+
for gl_item in general_ledger:
875+
fin_bal_currency_ids = []
876+
fin_bal_currency_id = gl_item["currency_id"]
877+
if gl_item["currency_id"]:
878+
continue
879+
gl_item["fin_bal"]["bal_curr"] = gl_item["init_bal"]["bal_curr"]
880+
if "move_lines" in gl_item:
881+
for ml in gl_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+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
887+
if ml_currency_id not in fin_bal_currency_ids:
888+
fin_bal_currency_ids.append(ml_currency_id)
889+
elif "list_grouped" in gl_item:
890+
fin_bal_currency_ids = []
891+
for lg_item in gl_item["list_grouped"]:
892+
lg_item["fin_bal"]["bal_curr"] = lg_item["init_bal"]["bal_curr"]
893+
for ml in lg_item["move_lines"]:
894+
ml_currency_id = (
895+
ml["currency_id"][0] if ml["currency_id"] else False
896+
)
897+
if ml_currency_id and ml_currency_id != company.currency_id.id:
898+
lg_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
899+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
900+
if ml_currency_id not in fin_bal_currency_ids:
901+
fin_bal_currency_ids.append(ml_currency_id)
902+
# If there is only 1 currency, we set that one as fin_bal_currency_id
903+
# The use of different move lines with different currencies (EUR + GBP)
904+
# will be excluded. We use a different field to avoid showing the initial
905+
# balance and/or distorting data.
906+
if not gl_item["currency_id"] and len(fin_bal_currency_ids) == 1:
907+
fin_bal_currency_id = fin_bal_currency_ids[0]
908+
gl_item["fin_bal_currency_id"] = fin_bal_currency_id
855909
return {
856910
"doc_ids": [wizard_id],
857911
"doc_model": "general.ledger.report.wizard",

account_financial_report/report/general_ledger_xlsx.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ def _generate_report_content(self, workbook, report, data, report_data):
347347
"final_balance": account["fin_bal"]["balance"],
348348
}
349349
)
350-
if foreign_currency and account["currency_id"]:
350+
if foreign_currency and account["fin_bal_currency_id"]:
351351
account.update(
352352
{
353-
"final_bal_curr": account["fin_bal"]["bal_curr"],
353+
"final_bal_curr": total_bal_curr,
354+
"currency_id": account["fin_bal_currency_id"],
354355
}
355356
)
356357
self.write_ending_balance_from_dict(account, report_data)

0 commit comments

Comments
 (0)