注册报表:
@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.))