Skip to content

Commit

Permalink
[IMP] account_financial_report: Add Amount cur. to General Ledger tot…
Browse files Browse the repository at this point in the history
…als if the account has not set currency

Related to #1235 (comment)
  • Loading branch information
victoralmau committed Oct 17, 2024
1 parent 3b04d20 commit 2240fe7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,38 @@ def _get_report_values(self, docids, data):
account[grouped_by] = False
del account["list_grouped"]
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
# Set the 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 = []
if not gl_item["currency_id"] and "move_lines" in gl_item:
gl_item["fin_bal"]["bal_curr"] = gl_item["init_bal"]["bal_curr"]
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 867 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L867

Added line #L867 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 869 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L869

Added line #L869 was not covered by tests
elif not gl_item["currency_id"] and "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"]

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

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L879

Added line #L879 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 881 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L881

Added line #L881 was not covered by tests
# If there is only 1 currency, we set that one as currency_id
# The use of different move lines with different currencies (EUR + GBP)
# will be excluded.
if not gl_item["currency_id"] and len(fin_bal_currency_ids) == 1:
gl_item["currency_id"] = fin_bal_currency_ids[0]

Check warning on line 886 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

Added line #L886 was not covered by tests
return {
"doc_ids": [wizard_id],
"doc_model": "general.ledger.report.wizard",
Expand Down

0 comments on commit 2240fe7

Please sign in to comment.