Printed business documents: the shared document parts
A printed business document has the same anatomy whatever it is: the company letterhead, a title with the document’s
kind and number, the partner’s address, a row of dates and references, a table of lines, the totals, and closing
notes. The web addon ships each part as a QWeb template (addons/web/data/report_documents.xml) so that an
invoice, a sales order and a delivery slip look like one family and an addon writes only what is its own: which
values go where.
A report calls web.html_container and web.external_layout once around its records, as every report does (the
letterhead and the footer with the page counter come from web.external_layout), and calls the parts inside the
page of each record. How a report is declared and put under the Print menu is in the report library guide
(docs/addon-guide/reports.md, “Declaring a report and printing it”).
The parts
Section titled “The parts”Arguments are written on the t-call. A label is given as label.translate="Due Date": the text is a term of the
document’s language, as a text node of the template is (translated template terms are not loaded yet, so a label
prints as written; a translation, once loaded, prints as text and is never evaluated). Any other argument is an expression (number="o.name",
columns="5"); a text literal inside an expression is written in quotes (text="'Hardware'") and is not
translated. Every argument a part names must be given: pass False for an empty one.
| Template | Arguments | Body | Prints |
|---|---|---|---|
web.document_title | title, number, status | none | The kind (title) in the accent colour followed by the number, and at the right the status in red, for a document that is not final (Draft, Cancelled). number and status may be False. |
web.document_addresses | none | one or two web.document_address | The address row: blocks side by side, each half the width. |
web.document_address | address (a res.partner record), label | none | A small label, the partner’s display name in bold, street, second street, zip and city, state and country, and its tax ID when set. Empty lines are left out. |
web.document_info | none | web.document_info_item parts | A row of labelled values, four to a line; a fifth item starts a second line on the same grid. |
web.document_info_item | label | the value | A small grey label over the value in bold. Guard the call with t-if when the value may be empty. |
web.document_lines | none | the thead and tbody of the table | The lines table at the full width. The thead row repeats at the top of every page; a row is never split across two pages unless it is about half a page tall or more. |
web.document_line_section | columns, text | none | A section title in bold over all columns of the table. |
web.document_line_note | columns, text | none | A note in grey italics over all columns. |
web.document_totals | none | web.document_total_row and web.document_total_grand parts | The totals in the right half of the page, kept together on one page. |
web.document_total_row | label | the amount | One row: untaxed amount, one tax group, a payment. |
web.document_total_grand | label | the amount | The total or the amount due, larger and in bold, the amount in the accent colour. |
web.document_note | label (or False) | the text | A notes or terms block in small type, kept on one page. |
web.document_signatures | none | web.document_signature parts | A row of signature lines with room above them, three to a line. |
web.document_signature | label | none | A line with who signs under it. |
The lines table is the caller’s: it decides the columns and writes the thead row and the rows of tbody. Put
text-end on the th and td of every number column. A monetary field printed with t-field takes the currency
of its record (symbol, position and decimals); a computed amount takes the record’s currency with
t-options="{'widget': 'monetary', 'display_currency': o.currency_id}". Print a quantity with its unit:
<span t-field="line.quantity"/> <span t-field="line.product_uom_id.name"/>. Columns are sized from their content:
short number columns are as wide as their longest value, and the description takes the rest and wraps. A section or
note row spans the table, so it does not widen the first column.
There is no amount-in-words part: the engine has no number-to-words formatter.
A complete report
Section titled “A complete report”A sales quotation of a fictional addon my_sales (model my_sales.order with a partner, a date, a salesperson, lines
and amounts), in views/my_sales_reports.xml:
<template id="report_order_document"> <div class="page"> <t t-set="status" t-value="False"/> <t t-if="o.state == 'draft'" t-set="status">Draft</t> <t t-call="web.document_title" title.translate="Quotation" number="o.name" status="status"/> <t t-call="web.document_addresses"> <t t-call="web.document_address" address="o.partner_id" label.translate="Customer"/> <t t-if="o.partner_shipping_id" t-call="web.document_address" address="o.partner_shipping_id" label.translate="Delivery Address"/> </t> <t t-call="web.document_info"> <t t-call="web.document_info_item" label.translate="Order Date"><span t-field="o.date_order"/></t> <t t-if="o.user_id" t-call="web.document_info_item" label.translate="Salesperson"><span t-field="o.user_id"/></t> <t t-if="o.client_ref" t-call="web.document_info_item" label.translate="Your Reference"><span t-field="o.client_ref"/></t> </t> <t t-call="web.document_lines"> <thead> <tr> <th>Description</th> <th class="text-end">Quantity</th> <th class="text-end">Unit Price</th> <th class="text-end">Amount</th> </tr> </thead> <tbody> <t t-foreach="o.line_ids" t-as="line"> <t t-if="line.display_type == 'line_section'" t-call="web.document_line_section" columns="4" text="line.name"/> <t t-elif="line.display_type == 'line_note'" t-call="web.document_line_note" columns="4" text="line.name"/> <tr t-else=""> <td t-field="line.name"/> <td class="text-end"><span t-field="line.quantity"/> <span t-field="line.product_uom_id.name"/></td> <td class="text-end" t-field="line.price_unit"/> <td class="text-end" t-field="line.price_subtotal"/> </tr> </t> </tbody> </t> <t t-call="web.document_totals"> <t t-call="web.document_total_row" label.translate="Untaxed Amount"><span t-field="o.amount_untaxed"/></t> <t t-call="web.document_total_row" label.translate="Taxes"><span t-field="o.amount_tax"/></t> <t t-call="web.document_total_grand" label.translate="Total"><span t-field="o.amount_total"/></t> </t> <t t-if="o.note" t-call="web.document_note" label.translate="Terms and Conditions"><span t-field="o.note"/></t> <t t-call="web.document_signatures"> <t t-call="web.document_signature" label.translate="Customer Signature"/> </t> </div></template>
<template id="report_order"> <t t-call="web.html_container"> <t t-call="web.external_layout"> <t t-foreach="docs" t-as="o"> <div t-att-class="None if o_first else 'page-break-before'"> <t t-call="my_sales.report_order_document"/> </div> </t> </t> </t></template>
<record id="action_report_order" model="ir.actions.report"> <field name="name">Quotation / Order</field> <field name="model">my_sales.order</field> <field name="report_type">qweb-pdf</field> <field name="report_name">my_sales.report_order</field> <field name="print_report_name">'Order - ' + (object.name or 'Draft')</field> <field name="binding_model_id" ref="my_sales.model_my_sales_order"/> <field name="binding_type">report</field></record>The status is set with a t-set body, so the word is translated like any other text of the template.
What the print profile gives these parts
Section titled “What the print profile gives these parts”The parts use only the print profile of the report library. These of its rules exist for them:
colspanon atdorth(literal ort-att-colspan, 1 to 1,000) spans that many columns; the table counts its columns by span.rowspanabove one is still refused by name.- A
rowwhosecol-Nchildren add up to more than twelve goes on to further lines, as a Bootstrap row does; every line keeps the twelve-column grid. A row with a sharingcolorcol-autostays one line. - A
name.translateargument of at-callis a term of the program’s language. - A table column whose every cell carries
text-endis a number column: it is as wide as its longest amount, so an amount never wraps, and the text columns (description, taxes) share the rest of the width and wrap inside their own column. Mark every number cell and itsthwithtext-end. A monetary value prints its currency symbol with a non-breaking space, so the symbol stays with its number; write when you print an amount by hand. - When the number columns and the short columns together need more than seven tenths of the page width at the
base size (many columns, or amounts of fourteen digits), the whole table prints one size smaller (nine tenths),
every cell of it, instead of wrapping or overlapping an amount. The text columns keep at least three tenths of
the width: when the number columns need more than seven tenths even one size smaller, every column shares the
width by its text and a long amount may wrap inside its column. List one tax per line (
<br/>between them), so the taxes column stays narrow. - A row, a note, the totals and the signatures are kept on one page. One estimated taller than half the page body (a very long line description, terms of more than a page) may break across pages instead of running past the bottom margin; the estimate counts characters and line breaks, so a row a little under half a page may break too.
- A comprehension,
sumorjoiniterates a recordset record by record:sum([line.price_subtotal for line in o.order_line if not line.display_type]).
The accent colour (#086d71) is the one colour these parts add; an addon or a database that wants another inherits
web.document_title and web.document_total_grand. A company setting for document colours does not exist yet.