PDF-rapporter

Med Studio kan du redigera befintliga PDF-rapporter (t.ex. fakturor, offerter, etc.) eller skapa nya.

Standardlayout

The default layout of reports is managed outside Studio. Go to Settings, then, in the Companies section of the main page, click Configure Document Layout. Layout settings are company-specific but apply to all reports.

Tips

You can see how the different settings affect the report layout in the report preview on the right side of the Configure your document layout window. When creating or editing a report, you can see a preview of the report by clicking Print preview on the left side of the screen.

Använd följande inställningar:

  • Layout: Seven layouts are available:

    Exempel på layout för ljusrapport
  • Background: The following backgrounds are available:

    • Blank: Nothing is displayed.

    • Demo logo: A demo logo is displayed in the background.

    • Custom: Upload a custom background image.

  • Text: Eight fonts are available: Lato, Roboto, Open Sans, Montserrat, Oswald, Raleway, Tajawal (which supports Arabic and Latin scripts), and Fira Mono. Go to the Google Fonts website to preview them.

  • Färger: Ändra de primära och sekundära färger som används för att strukturera rapporter. Standardfärgerna genereras automatiskt baserat på färgerna i logotypen.

  • Address: The company name and address are displayed in the header of external reports. You can add multiple lines of text.

  • Tagline: This is displayed in the header of external reports using the Light, Striped, Bubble, Wave and Folder layouts and in the footer of external reports using the Boxed and Bold layouts. You can add multiple lines of text.

  • Paper format: This defines the default paper size of reports. You can select A4 (21 cm x 29.7 cm) and US Letter (21.59 cm x 27.54 cm). This can also be defined for individual reports in the Paper format field in Studio.

    Observera

    Other paper formats may be available depending on which apps or modules you have installed, for example, label sheets for the Inventory app or event badges for the Events app.

Skapa nya PDF-rapporter

To create a new report for a model, (e.g., sales orders) access the model, click the (Toggle Studio) button, then click Reports. Click New and, in the popup window that opens, select the type of report. This is solely used to determine what is displayed in the header and footer:

När du har skapat rapporten kan du börja redigera den.

Redigera PDF-rapporter

To access the reports available for a model, access the model, click the (Toggle Studio) button, then click Reports. Select an existing report to open it.

Alternativt kan du också öppna Studio, klicka på Reports och söka efter en specifik rapport eller modell.

Viktigt

It is strongly recommended to duplicate the standard report and make changes in the duplicated version. To duplicate a report, hover the mouse pointer on the top right corner of the report, click the (vertical ellipsis) icon, and then select Duplicate.

Duplicera en PDF-rapport

Alternativ

Once you have selected or created a report, you can use the options in the left part of the screen to:

  • Change the Report name: The new name is applied everywhere (in Studio, in the Print menu under the (gear) icon in the form view, and in the PDF file name).

  • Modify the Paper format: If no value is selected, the format defined in the default layout is used.

  • Show in print menu: to add the report to the Print menu in the form view.

  • Reload from attachment: för att spara rapporten som en bilaga på posten första gången den genereras och ladda om originalversionen av rapporten när som helst därefter. Detta är ett lagkrav för fakturor och används främst i detta fall.

  • Begränsa synlighet till grupper: för att begränsa tillgängligheten för PDF-rapporten till specifika användargrupper.

  • Redigera källor: för att ändra rapporten direkt i XML-filen.

  • Reset report: för att ta bort alla ändringar som gjorts i rapporten och återställa den till standardversionen.

  • Print preview: för att generera och ladda ner en förhandsgranskning av rapporten.

Redaktör för rapporten

The report editor allows you to modify the content and formatting of the report.

Tips

  • You can Undo or Redo changes using the related buttons or the shortcuts CTRL + Z and CTRL + Y.

  • Ändringar sparas automatiskt när du lämnar rapporten eller manuellt med knappen Save.

  • Du kan återställa rapporten till standardversionen genom att klicka på knappen Återställ rapport i den vänstra delen av skärmen.

Viktigt

Redigering av sidhuvud och sidfot i en rapport påverkar alla standardrapporter och anpassade rapporter.

Villkorliga block

De streckade rektanglarna representerar villkorliga block (if/else-satser). Dessa används för att visa/dölja innehåll baserat på specifika villkor. Klicka på blocket för att visa villkoren.

Visa villkor som gäller för ett block.

Välj ett värde för att förhandsgranska dess motsvarande utdata och redigera den vid behov.

Förhandsgranska resultatet av ett annat villkor.

Observera

Conditions can only be edited in the XML.

Annat innehåll

Det finns två typer av textinnehåll i rapporter:

  • Static text, i.e., the text that is not highlighted in blue, which can be modified directly in the editor.

  • Dynamic text, i.e., the text that is highlighted in blue, which is replaced by field values when the report is generated, e.g., the sales order number or the quotation date.

You can add content (e.g., fields, lists, tables, images, banners, etc.) to the report using commands. Type / to open the powerbox, then type the command’s name or select it from the list.

Om du vill lägga till statisk text i rapporten skriver du texten där du vill ha den.

För mer avancerade ändringar kan du redigera rapporten i XML direkt.

Lägg till ett fält

To add a field, type / and select the Field command. In the list that opens, select or search for the field; click the right arrow next to the field name to access the list of related fields if needed. Then, specify the default value that will be shown if the field is not completed in the record and press Enter.

Välj ett relaterat område.
Add or edit a table

There are two types of tables in reports:

  • Static tables, which are used to display static text or fields. For this type of table, you define the number of columns and rows when adding the table.

  • Dynamic tables, which are used to display data from relational fields. For this type of table, you only define the number of columns when adding the table. The number of rows in the generated report will be determined by the number of records in the related model that are linked with the current model.

    Example

    In a sales order report, a dynamic table is used to show the order lines related to the sales order. If the sales order contains 10 order lines, the table in the generated report has 10 rows; if it contains two order lines, the table has two rows.

Add or edit a static table

To add a static table, type / and select the Table command. Determine the number of columns and rows for the table. Once the table has been added, you can start editing it.

You can insert, move and delete columns and rows using the table tools. Position the cursor on top of the column or to the left of the row then click the purple rectangle and select an option.

List of available options for editing table structure.

To resize a column, drag the column border to the desired position; reset all columns to their standard size by selecting Reset Size from the table tools.

Add the field of your choice in a cell or add static text by typing.

Tips

To add text in a structured way without using a table, you can use columns. Add columns by typing / and selecting the appropriate command: 2 columns, 3 columns or 4 columns.

Add or edit a dynamic table

Observera

  • Only relations of type one2many or many2many can be displayed as dynamic tables.

  • An existing dynamic table in a standard report has a more complex structure than a dynamic table you add yourself. For such tables, it is possible to insert or delete columns; it is not possible to move columns or to insert, move or delete rows.

To add a dynamic table, type / and select the Dynamic Table command. In the list that opens, select or search for the relation the table will be based on and press Enter. Once the table has been added, you can start editing it.

You can insert, move and delete columns using the table tools, as for a static table. It is also possible to insert static rows that will appear above or below the generated rows.

To add a field to a cell, delete any placeholder text then add the field of your choice. The dialog box that opens shows the source object for the field (e.g., the Order Lines model) and the list of available fields.

List of available fields for the sale order lines model.

Replace the Column name label by the label of your choice.

Observera

The default row automatically iterates over the field’s content, generating a row on the report for each field value (e.g., one row per order line).

Formatering

To format text in the report, select it, then format it using the options in the text editor.

Formatera text med hjälp av textredigeraren.

Redigera rapportens XML

Varning

Om du ändrar XML direkt kan det leda till rapportproblem under uppgraderingar. Om detta händer kopierar du helt enkelt dina ändringar från den gamla databasen till den uppgraderade databasen.

För att redigera rapportens XML, klicka på Redigera källor i den vänstra rutan.

Exempel

To change how data is presented in your report, you can modify a field’s default widget manually. In the example below, the order date shows the date and time by default, while the unit price defaults to a precision of two decimal places.

<div class="oe_structure">
 <span t-field="doc.date_order"/>
 <span t-field="doc.price_unit"/>
</div>

By using t-options, in this case the widget option, these fields can be modified to show only the date and a precision of four decimal places, respectively:

<div class="oe_structure">
 <span t-field="doc.date_order" t-options="{'widget': 'date'}"/>
 <span t-field="doc.price_unit" t-options="{'widget': 'float', 'precision': 4}"/>
</div>

Om du vill visa/dölja innehåll baserat på specifika villkor, kan du manuellt lägga till if/else kontrollsatser i rapportens XML.

Om du t.ex. vill dölja en anpassad datatabell om det inte finns några taggar kan du använda attributet t-if för att definiera villkoret, som sedan utvärderas som True eller False. Tabellen visas inte om det inte finns några taggar i citatet.

<!-- table root element -->
<table class="table" t-if="len(doc.tag_ids) > 0">
    <!-- thead = table header, the row with column titles -->
    <thead>
        <!-- table row element -->
        <tr>
            <!-- table header element -->
            <th>ID</th>
            <th>Name</th>
        </tr>
    </thead>
    <!-- table body, the main content -->
    <tbody>
        <!-- we create a row for each subrecord with t-foreach -->
        <tr t-foreach="doc.tag_ids" t-as="tag">
            <!-- for each line, we output the name and price as table cells -->
            <td t-out="tag.id"/>
            <td t-out="tag.name"/>
        </tr>
    </tbody>
</table>

Om du vill visa ett annat block om t-if-satsen utvärderas som False, kan du ange det med hjälp av t-else-satsen. t-else-blocket måste följa direkt efter t-if-blocket i dokumentstrukturen. Det finns ingen anledning att ange något villkor i t-else-attributet. Som exempel kan vi visa ett snabbt meddelande som förklarar att det inte finns några taggar i citatet:

<!-- table root element -->
<table class="table" t-if="len(doc.tag_ids) > 0">
    <!-- thead = table header, the row with column titles -->
    <thead>
        <!-- table row element -->
        <tr>
            <!-- table header element -->
            <th>ID</th>
            <th>Name</th>
        </tr>
    </thead>
    <!-- table body, the main content -->
    <tbody>
        <!-- we create a row for each subrecord with t-foreach -->
        <tr t-foreach="doc.tag_ids" t-as="tag">
            <!-- for each line, we output the name and price as table cells -->
            <td t-out="tag.id"/>
            <td t-out="tag.name"/>
        </tr>
    </tbody>
</table>
<div class="text-muted" t-else="">No tag present on this document.</div>

Genom att använda notationen t-if/t-else visar rapportredigeraren att dessa avsnitt är ömsesidigt uteslutande och bör visas som villkorliga block:

Visa förhandsgranskning om det finns taggar.

Du kan byta villkor med hjälp av editorn för att förhandsgranska deras resultat:

Visa förhandsgranskning om det inte finns några taggar.

Om du vill ha flera alternativ kan du också använda t-elif-direktiv för att lägga till mellanliggande villkor. Så här ändras t.ex. titeln på försäljningsorderrapporter baserat på villkoret för det underliggande dokumentet.

<h2 class="mt-4">
    <span t-if="env.context.get('proforma', False) or is_pro_forma">Pro-Forma Invoice # </span>
    <span t-elif="doc.state in ['draft','sent']">Quotation # </span>
    <span t-else="">Order # </span>
    <span t-field="doc.name">SO0000</span>
</h2>

Titeln Pro-Forma Invoice används beroende på vissa kontextuella villkor. Om dessa villkor inte är uppfyllda och dokumentets status är antingen draft eller sent, då används Quotation. Om inget av dessa villkor är uppfyllda är rapportens titel Order.

Working with images in a report can be challenging, as precise control over image size and behavior is not always obvious. You can insert image fields using the report editor (by using the Field command), but inserting them in XML using the t-field directive and accompanying t-options attributes provides better sizing and positioning control.

Följande kod matar t.ex. ut fältet image_128 för radens produkt som en 64px bred bild (med en automatisk höjd baserad på bildens bildförhållande).

<span t-field="line.product_id.image_128" t-options-widget="image" t-options-width="64px"/>

Följande alternativ är tillgängliga för bildwidgets:

  • width: bildens bredd, vanligtvis i pixlar eller CSS-längdenheter (t.ex. rem) (lämna tomt för automatisk bredd).

  • height: bildens höjd, vanligtvis i pixlar eller CSS-längdenheter (t.ex. rem) (lämna tomt för automatisk höjd).

  • class: CSS-klasser som tillämpas på img-taggen; Bootstrap-klasser är tillgängliga.

  • alt: alternativ text för bilden

  • style: stilattribut; det gör att du kan åsidosätta stilar mer fritt än med Bootstrap classes.

Dessa attribut måste innehålla strängar, dvs. text omsluten av citattecken inom citattecken, t.ex. t-options-width="'64px'" (eller, alternativt, ett giltigt Python-uttryck).

Observera

Bildwidgeten kan inte användas på en img-tagg. Ställ istället in t-field-direktivet på en span (för inline-innehåll) eller div (för blockinnehåll) nod.

Låt oss till exempel lägga till en kolumn med produktbilden i offert-tabellen:

<table class="table table-sm o_main_table table-borderless mt-4">
    <thead style="display: table-row-group">
        <tr>
            <th>Image</th>
            <th name="th_description" class="text-start">Description</th>
            <th>Product Category</th>
            <th name="th_quantity" class="text-end">Quantity</th>
            <th name="th_priceunit" class="text-end">Unit Price</th>
[...]
        <t t-foreach="lines_to_report" t-as="line">
            <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>
            <tr t-att-class="'bg-200 fw-bold o_line_section' if line.display_type == 'line_section' else 'fst-italic o_line_note' if line.display_type == 'line_note' else ''">
                <t t-if="not line.display_type">
                   <td>
                       <span t-field="line.product_template_id.image_128"
                             t-options-widget="'image'"
                             t-options-width="'64px'"
                             t-options-class="'rounded-3 shadow img-thumbnail'"
                           />
                   </td>
                    <td name="td_name"><span t-field="line.name">Bacon Burger</span></td>
                    <td t-out="line.product_id.categ_id.display_name"/>

Attributet t-options-width begränsar bildbredden till 64 pixlar, och Bootstrap-klasserna som används i t-options-class skapar en miniatyrliknande ram med rundade hörn och en skugga.

Lägg till en kolumn med produktbilden i offert-tabellen.