odoo/upgrade-util#360

Created by Upgrade, Oskar Wielgos (owi)

Blocked

label
odoo-dev:master-add_report-owi
head
64d430bcc10087d0056c5e93eeef115f4a1bee9c
odoo/upgrade odoo/upgrade-util
master #8968 missing r+ #360 missing r+

[ADD] util/report: util.add_report

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())

<img width="1151" height="635" alt="image" src="https://github.com/user-attachments/assets/64542831-f142-484c-becc-ff200297287a" />

Example 2

util.add_report(header=&#34;Simple note&#34;, summary=&#34;A detailed description of the change.&#34;)

<img width="294" height="75" alt="image" src="https://github.com/user-attachments/assets/aea1c9c6-c7d8-4692-aa82-71ff460e0cdf" />

Example 3

msg = &#34;&#34;&#34;
This is some text in **bold**.  

This is a line  
that should break.

- Item one
- Item two
    - Sub-item

And some _italic_ text.
&#34;&#34;&#34;
util.add_report(header=&#34;MD note&#34;, summary=msg, report_format=&#34;md&#34;)

<img width="324" height="198" alt="image" src="https://github.com/user-attachments/assets/0c4a9324-cca9-4e4a-834d-ea8ad8d71f63" />

Example 4

msg = &#34;&#34;&#34;
This is some text in **bold**.

| This is a line
| that should break.

* Item one
* Item two

  * Sub-item

And some *italic* text.
&#34;&#34;&#34;
util.add_report(header=&#34;RST note&#34;, summary=msg, report_format=&#34;rst&#34;)

<img width="411" height="202" alt="image" src="https://github.com/user-attachments/assets/75c92d4e-c1ae-4948-8665-ac4f5c5774ab" />

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):
    <img width="1527" height="540" alt="image" src="https://github.com/user-attachments/assets/5e9cf10d-2c7f-4898-b842-5bffd1ec231f" />