QWeb 報表設定篇

產生『序號』與『總數量』

使用 _index 參數即可自動生成序號

<t t-foreach="o.lines" t-as="p">
  <span t-esc="p_index">
</t>

也可使用迴圈來產生(不建議)

<t t-set="i" t-value="1" />
<t t-foreach="o.lines" t-as="p">
  <span t-esc="i">
  <t t-set="i" t-value="i+1"/>
</t>

if 判斷式

條件為 True 時

<t t-if="o.partner_id.parent_id">
<t t-if="o.partner_id.company_type == 'company'">

條件為 False 時

<t t-if="not o.partner_id.parent_id">
<t t-if="o.partner_id.company_type != 'company'">

計算『總數量』

總數量也是使用迴圈來處理的

原先的產品數量是這樣處理

<t t-foreach="o.lines" t-as="p">
  <span t-esc="p.quantity">

先設定變數 i = 0,每個產品的數量會加入 i,最後輸出即為總數量

<t t-set="i" t-value="0" />
<t t-foreach="o.lines" t-as="p">
  <span t-esc="i">
  <t t-set="i" t-value="i+p.quantity"/>
</t> 
<t t-esc="i" />

自訂紙張尺寸

首先需『啟用開發者模式』

接著到『設定』/『技術』/『動作』/『報表』/『Paper Format』

可以看到已經內建了幾種紙張尺寸了

如果報表中有呼叫系統內建的 Header,需要增加『上邊界』的大小

如果報表中無呼叫系統內建的 Header,『上邊界』的大小可設定為 8mm

PS:有一個 Bug 需要注意,雖然可從此處直接設定相關報表,但如果從此處移除相關報表時,也會將相關報表一併刪除!

 

命名下載報表的名稱

正常來說,下載報表的檔名會是『Odoo 報表名稱.pdf 』

如果報表名稱是『揀貨單明細』,檔案名稱就會是『揀貨單明細.pdf』

雖然使用上沒有問題,但生成多個檔案時,就會以揀貨單明細.pdf、揀貨單明細-1.pdf、揀貨單明細-2.pdf…..的方式呈現

不確定是否是 Bug,Save as Attachment Prefix 的設定並不會套用在下載檔案上

解決方案是安裝 Custom report filenames 這個 App,在報表中會多出『Download filename』這個欄位

可使用『揀_${o.name}.pdf』這樣的格式直接產生『揀_WH1-OUT-12149.pdf

目前還不確定如何產生日期,使用 time 或 strftime 時會跳出未定義,或許可以修改 APP 的程式碼加入 import time 或 import datetime 就可以使用了

 

 

參考資料:

[8.0] How can I create a custom report filename for Odoo (eg. SO039_2015_04_25.pdf)?

‘Save as attachment prefix’ doesn’t work?

How to generate serial number and total quantity in qweb report without parser file ?

[SOLVED]QWeb Report – How to repeate first page header on each page when printing on a custome size paper?

Set font to whole Page in Odoo Qweb Reports

Odoo: How to include a ‘page break’ / second page in custom report (pdf)?

Qweb if-else condition?

 

Download filename 參考格式:

訂購單_${o.name}.pdf
可用

訂購單_${o.name}_.strftime(“%Y-%m-%d”).pdf
後方的 .strftime(“%Y-%m-%d”) 不會生效

${(object.name or ”).replace(‘/’,’_’)}_${object.state == ‘draft’ and ‘draft’ or ” +’.xls’}
可用

${(object.client_order_ref or ”).replace(‘/’,’_’)}_
未測試

(object.state in (‘progress’,’manual’,’done’)) and ((object.name or ”).replace(‘/’,”)+’-‘+ time.ctime().split()[4] +’.pdf’)
後方的 time.ctime().split()[4] 不會生效

 

 

 

 

Odoo 製作 QWeb report 簡易版

自 Odoo 8.0 後,Odoo 採用 QWeb 為內部報表產生引擎

大致上語法只要參考 Webkit、其他 Qweb 報表、與 QWeb 手冊都可以順利解決

比較大的問題在於如何建立報表(Odoo 在這方面弄得很麻煩)

這篇教學是介紹該如何利用已有的報表來產生一個新報表

 

建立新報表(Report)與相關視圖(Views)

於『設定』/『技術』/『動作』/『報表』中找到想要建立模組的報表,點選上方『動作』中的『製作複本

修改『報表名稱』、『範本名稱』,範本名稱的後方需記錄起來,此範例為 report_ball_quotation

也一併記錄上方網址的 id = 1143

接著回到原始的 report,點選『搜索關連的 QWeb 視圖』,可以看到有三個視圖

我們需要製作 report_saleorderreport_saleorder_document 這兩個視圖的複本

製作 report_saleorder 的複本

修改視圖名稱(View Name)至關連報表名稱的 report_ball_quotation

也一併修改架構中的 sale.report_saleordersale.report_ball_quotation

sale.report_saleorder_document 至 sale.report_ball_quotation_document

此處需一併記錄 id = 1873

製作 report_saleorder_document 的複本

修改視圖名稱(View Name)至關連報表名稱的 report_ball_quotation_document

也一併修改架構中的 sale.report_saleorder_document 至 sale.report_ball_quotation_document

此處需一併記錄 id = 1874

建立相關視圖(Views)的外部 ID(External Identifiers)

於『設定』/『技術』/『序列與識別碼』/『External Identifiers』,點選上方藍色的『建立』按鈕

視圖 report_ball_quotation 對應的外部 ID

模組:sale

Model Name:ir.ui.view

External Identifier:report_ball_quotation

Record ID:1873

視圖 report_ball_quotation_document 對應的外部 ID

模組:sale

Model Name:ir.ui.view

External Identifier:report_ball_quotation_document

Record ID:1874

接著返回新建立的報表,點選『Add in the “Print” Menu』就大功告成了

最後在道 Sale Order 中,可以測試新建立的報表,可以再依照自己的需求進一步修改!

 

參考資料:

QWeb Reports

Creating Multiple Invoice Templates in Odoo v8(推薦看這篇教學)

Create Qweb Report(Youtube 影片,不是很容易懂)