Skip to content
ERPForAll DocsDevelopment

    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”).

    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.

    TemplateArgumentsBodyPrints
    web.document_titletitle, number, statusnoneThe 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_addressesnoneone or two web.document_addressThe address row: blocks side by side, each half the width.
    web.document_addressaddress (a res.partner record), labelnoneA 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_infononeweb.document_info_item partsA row of labelled values, four to a line; a fifth item starts a second line on the same grid.
    web.document_info_itemlabelthe valueA small grey label over the value in bold. Guard the call with t-if when the value may be empty.
    web.document_linesnonethe thead and tbody of the tableThe 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_sectioncolumns, textnoneA section title in bold over all columns of the table.
    web.document_line_notecolumns, textnoneA note in grey italics over all columns.
    web.document_totalsnoneweb.document_total_row and web.document_total_grand partsThe totals in the right half of the page, kept together on one page.
    web.document_total_rowlabelthe amountOne row: untaxed amount, one tax group, a payment.
    web.document_total_grandlabelthe amountThe total or the amount due, larger and in bold, the amount in the accent colour.
    web.document_notelabel (or False)the textA notes or terms block in small type, kept on one page.
    web.document_signaturesnoneweb.document_signature partsA row of signature lines with room above them, three to a line.
    web.document_signaturelabelnoneA 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 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.

    The parts use only the print profile of the report library. These of its rules exist for them:

    • colspan on a td or th (literal or t-att-colspan, 1 to 1,000) spans that many columns; the table counts its columns by span. rowspan above one is still refused by name.
    • A row whose col-N children 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 sharing col or col-auto stays one line.
    • A name.translate argument of a t-call is a term of the program’s language.
    • A table column whose every cell carries text-end is 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 its th with text-end. A monetary value prints its currency symbol with a non-breaking space, so the symbol stays with its number; write &#160; 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, sum or join iterates 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.