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

[14.0][FIX] account_financial_report: partner trial balance: sort by partner name #914

Merged

Conversation

alexis-via
Copy link
Contributor

On v14, trial balance report with "show partners details" = True:
BEFORE
bug_financial_report-before

AFTER:
bug_financial_report-after

More info:
With the current implementation, the partners that have debit = credit = 0 are always at the end. In the "before" screenshot, partner AAcorp has an initial balance, but it has debit = credit = 0 so it is displayed at the end.
With the current implementation, each account displays 2 blocks of partners, each block being in alphabetical order:

  1. partners that have moves in the period
  2. partners that don't have moves in the period

In python 3.7+, dictionary order is guaranteed to be insertion order. (warning: from my experience, insertion order may be different from print order !).

The trial balance report is built by the dictionary "total_amount". So, for a particular account, the order of the partners is the order of insertion of that partner in the total_amount[account_id] dictionary. This is handled by the method _compute_partner_amount() in report/trial_balance.py cf https://github.com/OCA/account-financial-reporting/blob/14.0/account_financial_report/report/trial_balance.py#L249 In that method, there is a first loop on tb_period_prt that inserts partner_id keys in total_amount[account_id] and a second loop on tb_initial_prt which inserts partner_id keys in total_amount[account_id] if that partner wasn't already inserted in the first loop. This explains the bug.

I'm not familiar with the code of account_financial_report, so I'm not sure that this PR is the best fix for the problem. But it solves the bug.

Copy link

@nibraun nibraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and approved !

@pedrobaeza pedrobaeza added this to the 14.0 milestone Sep 20, 2022
@pedrobaeza
Copy link
Member

@alexis-via are you going to forward-port this patch to v15 if I launch the merge command?

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Copy link

github-actions bot commented Nov 5, 2023

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 5, 2023
@pedrobaeza
Copy link
Member

@alexis-via please resolver the conflicts and fw-port it to upper versions.

@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 12, 2023
@alexis-via alexis-via force-pushed the 14-fix-partner_balance-sort_by_partner_name branch from 646a27a to 808c778 Compare February 28, 2024 00:06
@alexis-via
Copy link
Contributor Author

I propose that we wait until 2025 to merge this fix because:

  • it's not important, it can wait
  • in 2025, Odoo v18 will be out, so I'll have the pleasure to do one more forward port of this fix (when I wrote the patch in Sepember 2022, the latest version was 15, so there was only 1 forward port to do... it was not fun... 4 forward ports to do is just 4 times more fun !)
  • maybe the code of account_financial_report will change again in the meantime, so it will be more fun to rebase/reformat the patch to make it work on the new code

@alexis-via
Copy link
Contributor Author

BTW, the bug is still present in v14 with up-to-date code of the module account_financial_report, so this PR is still relevant.

@alexis-via alexis-via force-pushed the 14-fix-partner_balance-sort_by_partner_name branch 2 times, most recently from 9d1c02b to a77066e Compare February 28, 2024 00:40
@alexis-via alexis-via force-pushed the 14-fix-partner_balance-sort_by_partner_name branch from a77066e to 67147d7 Compare June 14, 2024 15:53
@alexis-via
Copy link
Contributor Author

This PR also fixes a crash in partner balance XLSX report. The crash is obsvious when you read the backtrace: confusion between ID and recordset. So I added a browse() to fix the crash.

Erreur:
Odoo Server Error

Traceback (most recent call last):
  File "/home/odoo/erp/reporting-engine/report_xlsx/controllers/main.py", line 38, in _report_routes_xlsx
    xlsx = report.with_context(context)._render_xlsx(docids, data=data)[0]
  File "/home/odoo/erp/account-financial-reporting/account_financial_report/models/ir_actions_report.py", line 25, in _render_xlsx
    return super(IrActionsReport, obj)._render_xlsx(docids, data)
  File "/home/odoo/erp/reporting-engine/report_xlsx_helper/models/ir_actions_report.py", line 19, in _render_xlsx
    return super()._render_xlsx(docids, data)
  File "/home/odoo/erp/reporting-engine/report_xlsx/models/ir_report.py", line 22, in _render_xlsx
    report_model.with_context(active_model=self.model)
  File "/home/odoo/erp/reporting-engine/report_xlsx/report/report_abstract_xlsx.py", line 105, in create_xlsx_report
    self.generate_xlsx_report(workbook, data, objs)
  File "/home/odoo/erp/account-financial-reporting/account_financial_report/report/abstract_report_xlsx.py", line 40, in generate_xlsx_report
    self._generate_report_content(workbook, objects, data, report_data)
  File "/home/odoo/erp/account-financial-reporting/account_financial_report/report/trial_balance_xlsx.py", line 239, in _generate_report_content
    self.write_account_footer(
  File "/home/odoo/erp/account-financial-reporting/account_financial_report/report/trial_balance_xlsx.py", line 266, in write_account_footer
    format_amt = self._get_currency_amt_header_format_dict(account, report_data)
  File "/home/odoo/erp/account-financial-reporting/account_financial_report/report/abstract_report_xlsx.py", line 601, in _get_currency_amt_header_format_dict
    "0" * line_object["currency_id"].decimal_places
AttributeError: 'int' object has no attribute 'decimal_places'

Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Oct 13, 2024
@alexis-via alexis-via force-pushed the 14-fix-partner_balance-sort_by_partner_name branch from b4b49d8 to 7e7adaf Compare October 22, 2024 14:47
@alexis-via
Copy link
Contributor Author

rebased.

@alexis-via
Copy link
Contributor Author

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 14.0-ocabot-merge-pr-914-by-alexis-via-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 9c7b7bc into OCA:14.0 Oct 22, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 88d2784. Thanks a lot for contributing to OCA. ❤️

@pedrobaeza
Copy link
Member

Please fw-port it to upper versions. You have even 2 even versions up there.

@alexis-via
Copy link
Contributor Author

@pedrobaeza I made all the forward ports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved merged 🎉 ready to merge stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants