PDF 報告¶
利用 Studio,你可 編輯現有 PDF 報告 (例如發票、報價單等),或 建立新的報告。
預設版面設計¶
The default layout of reports is managed outside Studio. Go to , then, in the Companies section, click Configure Document Layout. Layout settings are company-specific but apply to all reports.
小訣竅
You can see how the different settings affect the report layout in the report preview on the right, or download a sample invoice PDF by clicking Download PDF Preview.
有以下設定可用:
Layout: Four layouts are available:
Font: Seven fonts are available: Lato, Roboto, Open Sans, Montserrat, Oswald, Raleway, and Tajawal (which supports Arabic and Latin scripts). Go to the Google Fonts website to preview them.
公司標誌:按一下 編輯 按鈕,上載或更換標誌。此操作會將標誌加入至 公司 模型的公司記錄中。要存取此資料,可前往 ,然後在 公司 部份按一下 更新資訊。
顏色:變更報告結構所用的主色及輔助色。預設顏色會根據公司標誌顏色自動產生。
Layout background: The following backgrounds are available:
空白:不显示任何内容。
几何:背景显示几何图片。
Custom: upload a custom background image.
Company tagline: This is displayed in the header of external reports. You can add multiple lines of text.
Company details: These are displayed in the header of external reports. You can add multiple lines of text.
Paper format: to define the default paper size of reports. You can select A4 (21 cm x 29.7 cm), US Letter (21.59 cm x 27.54 cm), or QR codes page. This can also be defined for individual reports in the Paper format field in Studio.
建立新的 PDF 報告¶
To create a new report for a model, 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:
建立報告後,便可開始 編輯。
編輯 PDF 報告¶
To access the reports available for a model, access the model (e.g., sales orders), click the Toggle Studio button, then click Reports. Select an existing report to open it or create a new one.
小訣竅
或者,你也可開啟 Studio,按一下 報告,然後搜尋特定報告或模型。
重要
It is strongly recommended to duplicate the standard report and perform 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.
選項¶
Once you’ve 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, under the Print button, 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 in the Print menu available from the record.
從附件重新載入:首次產生報告時,將報告儲存為記錄的一項附件,而之後每次產生報告時,都重新載入原始版本。此設定是因應發票文件的法律要求,亦主要是在此情況下使用。
只限群組可見:只允許指定的 使用者群組 可查看及使用此 PDF 報告。
編輯來源:直接在 XML 檔案 中修改報告。
重設報告:捨棄所有對報告所做的修改,將其重設為標準版本。
預覽列印:產生及下載報告預覽。
報告編輯器¶
The report editor allows you to modify the formatting and contents of the report.
小訣竅
You can Undo or Redo changes using the related buttons or the shortcuts
CTRL ZandCTRL Y.你離開報告畫面時,變更會自動儲存。或者,你也可按一下 儲存 按鈕,手動儲存變更。
你可按一下螢幕左方的 重設報告 按鈕,將報告重設為標準版本。
重要
編輯報告的頁首及頁尾,會影響所有標準報告及自訂報告。
條件區塊¶
虛線方框代表 條件區塊 (if/else 條件語句),可用於根據特定條件,顯示或隱藏指定內容。按一下區塊可查看已設定的條件。
選擇一個值,以預覽其對應的輸出,並根據需要進行編輯。
備註
Conditions can only be edited in XML.
其他內容¶
報告可以有兩種文字內容:
Static text, i.e., the text that’s not highlighted in blue, which can be modified directly in the editor.
Dynamic text, i.e., the text that’s highlighted in blue, which is replaced by field values when the report is generated, e.g., the SO 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.
若想在報告中加入靜態文字,請在所需位置直接輸入文字。
若要進行較進階的修改,可 直接在 XML 檔案中編輯報告。
加入欄位¶
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 and press Enter.
Add a data table¶
Data tables are used to display relational fields. To add
a data table, type /, select the Dynamic Table command, and select the relation to be
displayed in the table.
備註
Only relations of type one2many or many2many can be displayed as data tables.
Once the table has been added, you can add columns using the table tools. Position the cursor on top of the column, then click the purple rectangle and select an option.
You can then insert the field of your choice in the columns. The dialog box that opens shows the source object for the field (e.g., the Tag model) and the list of available fields.
備註
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 tag). You can add static content rows above or below the generated rows using the table tools.
You can also add data tables by modifying the report’s XML.
格式設定¶
To format text in the report, select it, then format it using the options in the 文本编辑器.
編輯報告 XML¶
警告
直接修改 XML 檔案,可能會導致報告在 升級 過程出現問題。如果發生這種情況,只需將舊資料庫中的變更,複製至升級後的資料庫即可。
要編輯報告的 XML,請按一下左側面板的 編輯來源。
例子¶
Sometimes, tables are not properly recognized as such due to complex structures. In those cases, you can still modify them manually in the report XML. For example, with a sales order, you can find the following structure in the XML (simplified for documentation purposes):
<!-- table root element --> <table> <!-- thead = table header, the row with column titles --> <thead> <!-- table row element --> <tr> <!-- table header element --> <th>Name</th> <th>Price</th> </tr> </thead> <!-- table body, the main content --> <tbody> <!-- we create a row for each subrecord with t-foreach --> <tr t-foreach="record.some_relation_ids" t-as="line"> <!-- for each line, we output the name and price as table cells --> <td t-out="line.name"/> <td t-out="line.price"/> </tr> </tbody> </table>To modify a table, you must ensure that each row has the same number of data cells. For example, in the case above, you need to add a cell in the header section (with e.g., the column title) and another one in the body section with the field content (usually, with a
t-outort-fielddirective).<table> <!-- table root element --> <thead> <!-- thead = table header, the row with column titles --> <tr> <!-- table row element --> <th>Name</th> <!-- table header element --> <th>Price</th> <th>Category</th> </tr> </thead> <tbody> <!-- table body, the main content --> <tr t-foreach="record.some_relation_ids" t-as="line"> <!-- we create a row for each subrecord with t-foreach --> <td t-out="line.name"/> <!-- for each line, we output the name and price as table cells --> <td t-out="line.price"/> <td t-out="line.category_id.display_name"/> </tr> </tbody> </table>備註
Cells can span multiple rows or columns. For more information, go to the Mozilla Developer Network website.
For example, you can modify the Quotation/Order report to add a column to display the product category in the main table:
<table class="table table-sm o_main_table table-borderless mt-4"> <!-- In case we want to repeat the header, remove "display: table-row-group" --> <thead style="display: table-row-group"> <tr> <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> [...] <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 name="td_name"><span t-field="line.name">Bacon Burger</span></td> <td t-out="line.product_id.categ_id.display_name"/> <td name="td_quantity" class="text-end"> <span t-field="line.product_uom_qty">3</span> <span t-field="line.product_uom">units</span> <span t-if="line.product_packaging_id">![]()
To add a table in XML, you need to know the names of the fields and objects you wish to access and display. As an example, let’s add a table that details the tags on a sales order:
<!-- table root element -->
<table class="table">
<!-- 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>
備註
When adding tables manually, style them using Bootstrap classes, like the table class included in the
example above.
若想按特定條件顯示或隱藏內容,可在報告的 XML 中,手動加入 if/else 條件控制語句。
例如,若想在沒有標籤的情況下,隱藏自訂資料表格,可使用 t-if 屬性定義所需條件,該條件會被計算得出真假值,即 True (真)或 False (假)。如果引用中沒有標籤,該表格不會顯示。
<!-- 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>
若想在 t-if 語句計算結果為 False 時,顯示其他內容區塊,可使用 t-else 語句指定。 t-else 程式碼段落在文件結構中,必須緊接 t-if 程式碼段落之後。 t-else 的屬性無需設定任何條件。例如,我們可以顯示一個簡短訊息,指出引用中沒有標籤:
<!-- 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>
使用 t-if / t-else 語句後,報告編輯器便能知道這些部份不會同時出現,並且應該以條件區塊形式顯示:
你可使用編輯器切換不同條件,以預覽相應的輸出:
若想運用多個選項,也可使用 t-elif 指令,加入中間條件。例如,銷售單報告的標題可用此方法,按照底層參照文件的條件變化,去顯示不同的標題。
<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>
「 形式發票 」標題會根據具體情況使用。若未能符合這些條件,而且文件狀態為 草稿 或 已傳送 ,標題會顯示為「 報價單 」。若以上條件全部不符合,報告標題會顯示為「 訂單 」。
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.
例如,以下程式碼將資料行產品的 image_128 欄位,輸出為寬度 64 像素(px)的圖片。(圖片高度會根據圖片的寬高比自動調整。)
<span t-field="line.product_id.image_128" t-options-widget="image" t-options-width="64px"/>
圖片小工具有以下選項可用:
width:圖片寬度,通常以像素(px)或 CSS 長度單位(例如rem)表示,留空表示自動寬度。height:圖片高度,通常以像素(px)或 CSS 長度單位(例如rem)表示,留空表示自動高度。class:套用至img標籤的 CSS 類(class),支援使用 Bootstrap 類 。alt:圖片的替代文字style:style 樣式屬性,比使用 Bootstrap 類 更自由地覆蓋樣式。
這些屬性必須使用字串,即:用雙重引號括住的文字,例如 t-options-width="'64px'" ,或者使用有效的 Python 表達式。
備註
圖片小工具不可用於 img 標籤。請改用 t-field 指令,將其設定在 span (適用於嵌入文中內容)或 div (適用於區塊級別內容)節點之中。
例如,我們可在報價單的表格加入直欄,以顯示產品圖片:
<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"/>
t-options-width 屬性將圖片寬度限制為 64 像素,而 t-options-class 中使用的 Bootstrap 類,會建立一個類似縮圖、帶有圓角及陰影的邊框。