Skip to content

[ADD] util/report: util.add_report#360

Open
diagnoza wants to merge 2 commits into
odoo:masterfrom
odoo-dev:master-add_report-owi
Open

[ADD] util/report: util.add_report#360
diagnoza wants to merge 2 commits into
odoo:masterfrom
odoo-dev:master-add_report-owi

Conversation

@diagnoza
Copy link
Copy Markdown
Contributor

@diagnoza diagnoza commented Dec 1, 2025

Add a new function that replaces util.add_to_migration_reports.

The new function can automatically parse the provided data as a list of records. It can also limit the number of displayed records to prevent the upgrade report from growing too large.

The structure of the note is now defined within the function itself, standardizing its appearance.

Example usage

More examples will follow in odoo/upgrade, replacing the existing use of util.add_to_migration_reports.

Example 1

cr.execute(
        """
        SELECT p.id, p.name, p.city, p.comment, p.company_id, com.name FROM res_partner p
          JOIN res_company com
            ON p.company_id = com.id
        """
    )

summary = """
    This is a test of the utility method that is displaying a list of rows
    returned by an SQL query. The number of displayed rows is limited.
    """
row_format = "Partner with id {partner_link} works at company {company_link} in {city}, ({comment})"
columns = ("id", "name", "city", "comment", "company_id", "company_name")
links = {"company_link": ("res.company", "company_id", "company_name"), "partner_link": ("res.partner", "id", "name")}
util.add_report(header="Test of the new utility method", summary=summary, row_format=row_format, columns=columns, links=links, data=cr.fetchall())
image

Example 2

util.add_report(header="Simple note", summary="A detailed description of the change.")
image

Example 3

msg = """
This is some text in **bold**.  

This is a line  
that should break.

- Item one
- Item two
    - Sub-item

And some _italic_ text.
"""
util.add_report(header="MD note", summary=msg, report_format="md")
image

Example 4

msg = """
This is some text in **bold**.

| This is a line
| that should break.

* Item one
* Item two

  * Sub-item

And some *italic* text.
"""
util.add_report(header="RST note", summary=msg, report_format="rst")
image

Remaining details to discuss

  1. The introduction of env var to control limit.
  2. Enforce/assert the use of tuples instead of lists. Currently, it's possible to pass a list for columns (instead of a tuple) or a dictionary of lists for links (instead of a dictionary of tuples).
  3. How to handle depreciation of add_to_migration_reports.
  4. Indentation of the ir.ui.view record corresponding to the note is sometimes incorrect (previously there was the same issue):
image

@diagnoza diagnoza requested review from a team and aj-fuentes December 1, 2025 07:19
@robodoo
Copy link
Copy Markdown
Contributor

robodoo commented Dec 1, 2025

Pull request status dashboard

@diagnoza diagnoza force-pushed the master-add_report-owi branch 7 times, most recently from cc49acd to 7dae849 Compare December 1, 2025 08:16
@KangOl
Copy link
Copy Markdown
Contributor

KangOl commented Dec 1, 2025

upgradeci retry with always only crm

Copy link
Copy Markdown
Contributor

@aj-fuentes aj-fuentes left a comment

Choose a reason for hiding this comment

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

I think we can do some simplification here. Some suggestions below. Note that none of the suggestions were tested, take it as a guide.

Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
@diagnoza diagnoza force-pushed the master-add_report-owi branch 7 times, most recently from b40852a to 3525d5d Compare December 3, 2025 16:19
@diagnoza diagnoza requested review from KangOl and aj-fuentes December 3, 2025 16:19
@diagnoza diagnoza force-pushed the master-add_report-owi branch from 3525d5d to 7b3739f Compare December 3, 2025 16:21
Comment thread src/util/report.py Outdated
Comment thread src/util/report.py Outdated
Copy link
Copy Markdown
Contributor

@aj-fuentes aj-fuentes left a comment

Choose a reason for hiding this comment

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

Looks better. Please adapt the documentation to the same format we use elsewhere in this repo. Some suggestions above.

@diagnoza diagnoza force-pushed the master-add_report-owi branch 3 times, most recently from c48c6f9 to 64d430b Compare December 8, 2025 16:59
@diagnoza diagnoza requested a review from aj-fuentes December 8, 2025 17:00
Comment thread src/base/tests/test_util.py Outdated
@diagnoza diagnoza force-pushed the master-add_report-owi branch 3 times, most recently from d168aff to 4c0c518 Compare January 8, 2026 18:09
@diagnoza diagnoza requested a review from KangOl January 8, 2026 18:10
@diagnoza diagnoza force-pushed the master-add_report-owi branch 7 times, most recently from 3587982 to a0ba44f Compare January 14, 2026 15:47
@diagnoza diagnoza force-pushed the master-add_report-owi branch 2 times, most recently from 7a97a4a to 3036c32 Compare January 26, 2026 12:11
@diagnoza diagnoza force-pushed the master-add_report-owi branch from 3036c32 to bba2e7f Compare February 3, 2026 12:11
@diagnoza
Copy link
Copy Markdown
Contributor Author

diagnoza commented Feb 3, 2026

upgradeci retry

Comment thread src/util/report.py Outdated
Comment on lines +203 to +205
total = len(data) if total is None else total
limit = min(limit, total) if limit != -1 else total
disclaimer = "The total number of affected records is {}.".format(total)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't be explicit about the total unless it is explicitly passed. The reason is that maybe the caller just passed here a subset of the involved records in data, we cannot be sure that's the actual total number of affected records unless explicitly set.

Suggested change
total = len(data) if total is None else total
limit = min(limit, total) if limit != -1 else total
disclaimer = "The total number of affected records is {}.".format(total)
disclaimer = "The total number of affected records is {}.".format(total) if total else ""
total = len(data) if total is None else total
limit = min(limit, total) if limit != -1 else total

@diagnoza diagnoza force-pushed the master-add_report-owi branch 3 times, most recently from 9382655 to 670685e Compare February 10, 2026 20:40
@diagnoza
Copy link
Copy Markdown
Contributor Author

@aj-fuentes your latest suggestion is applied. Rebase not necessary because it's still up to date.

@diagnoza diagnoza requested a review from aj-fuentes February 18, 2026 09:27
@diagnoza diagnoza force-pushed the master-add_report-owi branch from 670685e to 9382655 Compare February 18, 2026 10:06
Comment thread src/util/report.py Outdated
@diagnoza
Copy link
Copy Markdown
Contributor Author

upgradeci retry

@diagnoza
Copy link
Copy Markdown
Contributor Author

@aj-fuentes @KangOl it's ready for another look.

@diagnoza
Copy link
Copy Markdown
Contributor Author

upgradeci retry

Comment thread src/util/report.py
link: get_anchor_link_to_record(rec_model, row_dict[id_col], row_dict[name_col])
for link, (rec_model, id_col, name_col) in links.items()
}
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Once we generate the link items (which are already escaped) I think we need to escape the remaining values in the dict.
For example imagine that row_format is "{some_field}" and in the dict we get {"some_field": "<script>window.alert('escaped')</script>"}

Suggested change
)
)
row_dict = {col: html_escape(val) for col, val in row_dict.items()}

cc: @KangOl

diagnoza added 2 commits May 5, 2026 12:56
Add a new function that replaces util.add_to_migration_reports.

The new function can automatically parse the provided data as a list of records.
It can also limit the number of displayed records to prevent the upgrade report from growing too large.

The structure of the note is now defined within the function itself, standardizing its appearance.
Use the new utility function designed specifically for
adding a report with a list of records.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants