odoo之Qweb的一些參數

註冊報表:

@string: 在打印按鈕那裏的顯示名稱

           @id:外id標識

           @name: 完整主模板名稱 模塊名.主板模名稱  用於管理和調用

           @file: 完整模板文件名 模塊名.模板文件名  用於更好地關聯模板

           @model:相關的模型顯示在那個模塊進行打印報表 通常在各視圖中的打印那裏會出現上面表示在採購訂單相關視圖時,

                   會出現“打印-詢價單/採購訂單”

           @report_type: 報表類型 是 qweb-pdf 或 qweb-html

           @report_name: 打印出來的文件名

           @groups_id:指定權限

        attachment_use="True"

        attachment="(object.state in('open','paid')) and

        ('INV'+(object.number or'').replace('/','')+'.pdf')"

        @attachment_use:使用附件,這樣不會一直查數據庫,只能當數據變化時纔會查數據庫

        @attachment:附件的名稱,當我們下載下來的文件名

報表模板

模板中的標籤統一都是以"t-"開始的。

t-name 用於指明模板的名稱

t-extend 用於指明該模板是繼承自另外哪一個模板,後面會帶父模板的名稱,如:t-extend=“Login"

t-jquery 一個jQuery的選擇器,後面指明選擇器的定義,如:t-jquery=".oe_logiin"

t-operation 一般跟在t-jquery後面,指明選擇器找到元素後執行的動作,其值有:append(追加)、replace(替換)

t-if 用於指明元素在頁面產生的條件,後面是帶一個javascript的表達式,返回True或False

條件表達式

     <tt-if="record.effort_estimate.raw_value > 0">

        <li>Estimate <fieldname="effort_estimate"/></li>

     </t>

    

     比較符號:

       lt(<)    lte(<=)  gt(>)   gte(>=)

注 <<= 不能用在表達式中,只能用字母代替

 

t-att-### 用於指明一個元素的屬性值,###是元素的屬性名稱,如:t-att-value="javascript表達式"

     # 屬性的字符替換   

        <spant-attf-class="oe_kanban_text{{

            record.date_deadline.raw_value and

            !(record.date_deadline.raw_value> (new Date()))

            ? '_red' : '_black' }}">

            <fieldname="date_deadline"/>

        </span>

        t-attf-prefixed  取代內容,上面的就是動態類

  t-att=mapping 鍵值對組成屬性,主要用多對

        <div t-at="{'a':1,'b':2}"/>

        結果:

         <div a="1"b="2"></div>

        

        t-att=pair 一對,這個對一個是鍵,後一個是值

         <div t-att="['a','b']"/>  <=>    <div t-att="('a','b')"/>   

        結果:

          <diva="b"></div>

 

t-foreach 用於指明一個循環調用,後面一般帶的是一個數組

還有一些變量

rec_index 從0開始循環索引

rec_size  要循環的記錄集大小

rec_first  第一個元素

rec_last   最後一個元素

rec_even   index爲偶數時爲真

rec_odd    index爲奇數時爲真

rec_parity  是偶數和奇數

rec_all  表示循環結束的標識

rec_value 循環一個字典時,的鍵的值

t-as 用於取得循環中的單個值,與t-foreach搭配使用,後面帶的是一個變量名,可以循環中使用變量取值

 

t-esc 用於一個文字輸出。過濾安全值,像html元素

t-raw  數據庫中的原始數據輸出

t-call 用於調用另外模板,後面帶一個模板的名稱

 

t-set 用於設定一個變量,後面帶變量的名稱,一般跟t-value搭配使用

 <t t-set="new_variable"t-value="True" />

        設置了變量 new_variable 的值 爲 True

        t-value 也可以是表達

         <t t-set="foo"t-value="2+1" >

        設置了變量foo值爲3

        t-value可以是一段html

        <t t-set="foo">

            <li>ok</li>

        </t>

        設置了變量foo 爲 <li>ok</li>

 

t-value 用於指定某個變量或元素的值

 

# 動態屬性

        <div>

            <t t-foreach="record.message_follower_ids.raw_value.slice(0,3)"

            t-as="rec">

              <imgt-att-src="kanban_image(

              'res.partner', 'image_small',rec)"

               class="oe_kanban_imageoe_kanban_avatar_smallbox"/>

            </t>

        </div

        t-att- prefixed 如 <img>的src  就可以 t-att-src="..."

       

 

 

      

       

    #設置屬性

        t-att-$name

        $name 是屬性名

        <div t-att-a="66" />

        結果:

          <diva="66"></div>

         

        t-attf-$name 用於混合,有字符串也有變量,變量用{{}}

        <t t-foreach="[1, 2, 3]"t-as="item">

            <li t-attf-class="row {{item_parity }}"><t t-esc="item"/></li>

        </t>

       

        t-att=mapping 鍵值對組成屬性,主要用多對

        <div t-at="{'a':1,'b':2}"/>

        結果:

         <div a="1"b="2"></div>

        

        t-att=pair 一對,這個對一個是鍵,後一個是值

         <div t-att="['a','b']"/>  <=>    <div t-att="('a','b')"/>   

        結果:

          <diva="b"></div>

       

 

 

<?xmlversion="1.0" encoding="utf-8"?>

<openerp>

    <data>

        <templateid="report_invoice">

           <tt-call="report.html_container">

                <tt-call="report.layout">

                    <div class ="page">

                       <div class='text-center'> 

                          <span>123</span> 

                      </div> 

                    </div>

                </t>

           </t>

        </template>

    </data>

</openerp>

       

docs:當前報表的記錄

doc_ids:記錄中的id集

list of ids for the docsrecords

doc_model:記錄的模型

model for the docs records

time:Python標準庫中引用的time

user:爲用戶打印報表的res.user記錄

res_company:當前用戶公司的記錄

 

翻譯報表需要定義兩個模板:

主要的報表模板、可翻譯文檔。

 

可以從可翻譯文檔中通過“t-lang”屬性調用主翻譯模板,(You can then call the translatable document from your main templatewith the attribute t-lang set to a language code (for

example fr or en_US) or to arecord field. You will also need to re-browse the related records with theproper context if you use fields that are translatable (like country

names, sales conditions, etc.))

發佈了112 篇原創文章 · 獲贊 25 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章