Use HTML as standard report template

Rational

  1. From our experience most of the setup are using LibreOffice to generate PDF version of some reports (usually: invoice, sale and delivery note).
    But launching LibreOffice each time is quite expensive. On some setup we use a dedicated host on which trytond-worker is mainly responsible of generating PDF.

  2. The maintenance of OpenDocument (even in flatten) is quite complicated. For some kind of changes we can edit them direct as plain/text (and so back-porting the change is doable) but others are almost impossible without using LibreOffice to edit them. This create a lot of unnecessary changes because the style rules are often renumbering and also different versions of LibreOffice generate different result.

  3. Maintaining a coherent style between all the standard report is quite complicated and difficult to enforce.

Proposal

To replace OpenDocument as default report format for standard Tryton report and use HTML with weasyprint.
So relatorio would become an optional dependency and weasyprint a required.

In order to maintain a coherent style, a default set of CSS rules is created by assembling general style rules that each module could define using an ordered and deactivable Model.
This style is included in every report using: <style py:content="style"></style>.
The user could also add style rules manually.
In standard the general style will be light such that it can be extended easily. For that I think it should follow the BEM convention by providing style for some minimal element like table, headers, address etc.

For the standard HTML part, it should be mainly semantic without any style.
A specific style could be defined on the ir.action.report the same way as the content is defined (and modified).

As all the reports will be changed, we could extend the standard layout of the module to store all the report template under a sub-directory report.

Nothing will be planned for the migration. Either users were using the standard reports and so they will be updated to the new standard, either they have custom report content which will stay.

Implementation

9 Likes

I celebrate the proposal! We only used core reporting once quite some time ago and we moved to HTML reports about 5 years ago and it is much better!

In the html_report module we make heavy use of jinja macros (which users can modify from the Tryton interface) so there’s no need to modify the whole report just to change how a particular section such as the lines of the sale or the customer address.

I’d suggest providing some kind of inheritance or customization that does not rely on completely changing the report.