iT邦幫忙

2021 iThome 鐵人賽

DAY 18
0
Software Development

Let's ODOO 開發與應用30天挑戰系列 第 18

Day18 Let's ODOO: Paper Format

今天我們來介紹Report paper format,有時候我們在生成report時候想要自己自定義的紙張格式,如直橫向、上下左右間距...等等,Odoo可以透過設定paper format來達到需求:

增加/data/student_paperformat.xml

<odoo>
    <data>
        <record id="paperformat_gary" model="report.paperformat">
            <field name="name">GARY PAPER</field>
            <field name="default" eval="True" />
            <field name="format">A4</field>
            <field name="page_height">0</field>
            <field name="page_width">0</field>
            <field name="orientation">Portrait</field>
            <field name="margin_top">50</field>
            <field name="margin_bottom">65</field>
            <field name="margin_left">7</field>
            <field name="margin_right">7</field>
            <field name="header_line" eval="False"/>
            <field name="header_spacing">45</field>
            <field name="dpi">90</field>
        </record>
    </data>
</odoo>

id:自定義,不重複即可

model:固定為report.paperformat

format:預定格式,預設為A4也可以填入A0 to A9, B0 to B10, Legal, Letter, Tabloid,…等等

dpi:輸出解析度,預設為90

orientationLandscape或Portrait,代表直向或橫向

margin_top :與上方邊距

margin_bottom :與下方邊距

margin_left :與左邊距

margin_right :與右邊距

page_height :紙張長度

page_width:紙張寬度

header_line :布林值,要不要顯示header line

header_spacing :與header距離

別忘了加入__manifest__裡:

'data': [
        'data/student_paperformat.xml'
		...
    ],

重新啟動以後我們在Setting → Business Document → Format內可以看到我們設定的名字,點選後並儲存

https://ithelp.ithome.com.tw/upload/images/20211003/20130896yNMM65JcDw.png

也可以點進去看我們的設定,也可以透過Odoo介面調整

https://ithelp.ithome.com.tw/upload/images/20211003/201308965jtZ02T3P8.png

在旁邊的Document Layout,也可以做簡單的樣式設定

https://ithelp.ithome.com.tw/upload/images/20211003/20130896MEIlT9GPmk.png
如此一來我們再回去印學生資料,就會根據我們的設定顯示了

https://ithelp.ithome.com.tw/upload/images/20211003/201308967ckXo2cquw.png

可以透過Odoo內的設定產出需要的樣式,結合前日所學,我們也可以指定format給report這樣一來印出的report也可以使用不同的樣式。


上一篇
Day17 Let's ODOO: Data Files
下一篇
Day19 Let's ODOO: Logging
系列文
Let's ODOO 開發與應用30天挑戰30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言