* Overview
QWeb is a template engine that generates HTML based on XML
First, the code example:
todo_task.py
-----------------------------
#-*-Coding:utf-8-*-
From OpenERP import models, fields
Class Todotask (models. Model):
_inherit = ' Todo.task '
Priority = fields. Selection (
[(' 0 ', ' low '), (' 1 ', ' Normal '), (' 2 ', ' High ')],
' Priority ', default= ' 1 ')
kanban_state = fields. Selection (
[(' Normal ', ' in Progress '),
(' blocked ', ' blocked '),
(' Done ', ' ready for next stage ')],
' Kanban state ', default= ' normal ')
----------------------------------
Todo_view.xml
----------------------------------
<?xml version= "1.0"?>
<openerp>
<data>
<!--Add Kanban view mode to the menu Action:-
<act_window id= "Todo_app.action_todo_task"
Name= "To-do Tasks"
Res_model= "Todo.task"
View_mode= "Kanban,tree,form,calendar,gantt,graph"
context= "{' Search_default_filter_my_tasks ': True}"/>
<!--Add Kanban View-
<record id= "To-do Task Kanban" model= "Ir.ui.view" >
<field name= "name" >to-do Task kanban</field>
<field name= "Model" >todo.task</field>
<field name= "Arch" type= "xml" >
<!--Empty for now, but the Kanban would go here! -
<kanban>
<templates>
<t t-name= "Kanban-box" >
<div class= "Oe_kanban_vignette" >
class= "Oe_kanban_image"/>
<div class= "Oe_kanban_details" >
<!--Title and Data content--
<a type= "Open" >
<field name= "Name"/>
</a>
<field name= "tags"/>
<ul>
<li>
<field name= "user_id"/>
</li>
<li>
<field name= "Date_deadline"/>
</li>
</ul>
<field name= "Kanban_state" widget= "Kanban_state_selection"/>
<field name= "Priority" widget= "priority"/>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
</data>
</openerp>
----------------------------------
# The style of the Kanban view
Vignette is the left side has a small plug-in, in the system is often used in customers, products, etc.
Card is commonly used in CRM for opportunities and opportunities, and is also used in project tasks
# Kanban View
<kanban> Top Elements
Common two fields priority, kanban_state
Priority shows the urgency of the project
Kanban_state show the stages of the project
<templates> has a name kanban-box with the following element <t t-name= "Kanban-box" >...</t>
<field> This is a field that, if used only for expression, is placed before <templates>, and the field is aggregated such as:
<field name= "effort_estimated" sum= "total effort"/>
<kanban> top-level elements support some properties
default_group_by Default grouping criteria
Default_order Default sorting criteria
Quick_create= "False" cannot quickly create an option
Class joins CSS Classes
CSS class, with two main oe_kanban_vignette and Oe_kanban_details
The T-ATT-SRC in can calculate the value of the SRC presence database in the image
# Actions in the Kanban view
In <a> there is a type attribute like the function in <button>
The values of type are:
Open: Opens the Form view
Edit: Open and Edit Form view
Delete: Deleting records
#卡片风格的看板视图
Example code:
<t t-name= "Kanban-box" >
<div class= "Oe_kanban_card" >
<div class= "Oe_dropdown_kanban oe_dropdown_toggle" >
<!--top-right Drop menu--
</div>
<div class= "Oe_kanban_content" >
<!--Option menu would go here! -
<a type= "Open" >
<field name= "Name"/>
</a>
<field name= "tags"/>
<ul>
<li>
<field name= "user_id"/>
</li>
<li>
<field name= "Date_deadline"/>
</li>
</ul>
<div class= "Oe_kanban_bottom_right" >
<field name= "Kanban_state"
widget= "Kanban_state_selection"/>
</div>
<div class= "Oe_kanban_footer_left" >
<field name= "Priority" widget= "priority"/>
</div>
</div>
</div>
</t>
* Add dynamic content to Qweb
#条件表达式
<t t-if= "record.effort_estimate.raw_value > 0" >
<li>estimate <field name= "Effort_estimate"/></li>
</t>
Compare symbols:
LT (<) LTE (<=) GT (>) GTE (>=)
Note < <= can not be used in an expression, but only in letters instead of
# Output Values T-esc and T-raw
<t t-esc= "Record.message_follower_ids.raw_value"/>
<t t-raw= "Record.message_follower_ids.raw_value"/>
T-ESC filter security values, like HTML elements
T-raw raw data in the database
# loops
<t t-foreach= "Record.message_follower_ids.raw_value" t-as= "Rec" >
<t t-esc= "Rec"/>;
</t>
T-foreach= "Record.message_follower_ids.raw_value.slice (0, 3)" can also be sliced
There are also some variables
Rec_index Cycle Index starting from 0
Rec_size the recordset size to loop
The first element of the Rec_first
Rec_last last Element
True if Rec_even index is even
Rec_odd index is true when it is odd
Rec_parity are even and odd
Rec_all indicates the end of the loop identification
Rec_value the value of a key when looping a dictionary
# Dynamic Properties
<div>
<t t-foreach= "Record.message_follower_ids.raw_value.slice (0, 3)"
t-as= "Rec" >
' Res.partner ', ' Image_small ', rec) "
class= "Oe_kanban_image Oe_kanban_avatar_smallbox"/>
</t>
</div
T-att-prefixed such as src can t-att-src= "..."
# Property of character substitution
<span t-attf-class= "oe_kanban_text{{
Record.date_deadline.raw_value and
! (Record.date_deadline.raw_value > (new Date ()))
? ' _red ': ' _black '} ' >
<field name= "Date_deadline"/>
</span>
T-attf-prefixed Replace the content, the above is the dynamic class
# variable Settings
<t t-set= "Red_or_black" t-value= "
Record.date_deadline.raw_value and
Record.date_deadline.raw_value LTE (new Date ())
? ' oe_kanban_text_red ': ' "/>
<span t-att-class= "Red_or_black" >
<field name= "Date_deadline"/>
</span>
T-set Set Variable T-value set the value of a variable
You can also use this
<t t-set= "Calendar_sign" >
<span class= "Oe_e" >& #128197;</span>
</t>
<t t-raw= "Calendar_sign"/>
# include other templates
<t t-name= "Follower_avatars" >
<div>
<t t-foreach= "Record.message_follower_ids.raw_value.slice (0, 3)"
t-as= "Rec" >
' Res.partner ', ' Image_small ', rec) "
class= "Oe_kanban_image Oe_kanban_avatar_smallbox"/>
</t>
</div>
</t>
。。。
<t t-call= ' Follower_avatars '/>
T-call Calling other templates
Flexible multiplexing
<t t-name= "Follower_avatars" >
<div>
<t t-foreach= "Record.message_follower_ids.raw_value.slice (0, Arg_max)"
t-as= "Rec" >
' Res.partner ', ' Image_small ', rec) "
class= "Oe_kanban_image Oe_kanban_avatar_smallbox"/>
</t>
</div>
</t>
。。。
<t t-call= ' Follower_avatars ' >
<t t-set= "Arg_max" t-value= ' 3 '/>
<t/>
# QWeb Other Instructions
<p t-att= "{' Class ': ' Oe_bold ', ' name ': ' test1 '}"/>
Results show
<p class= "Oe_bold" name= "Test1"/>
T-att Accepting Dictionaries
<p t-att= "[' Class ', ' Oe_bold ']"
Results show
<p class= "Oe_bold" >
# Card-Type plus menu
<div class= "Oe_dropdown_kanban oe_dropdown_toggle" >
<span class= "Oe_e" >í</span>
<ul class= "Oe_dropdown_menu" >
<t t-if= "widget.view.is_action_enabled (' edit ')" >
<li>
<a type= "Edit" >Edit...</a>
</li>
</t>
<t t-if= "widget.view.is_action_enabled (' delete ')" >
<li>
<a type= "Delete" >Delete</a>
</li>
</t>
<!--Color Picker option:-
<li>
<ul class= "Oe_kanban_colorpicker"
data-field= "Color"/>
</li>
</ul>
</div>
# Card Type plus color
<field name= "Color"/>
<div class= "Oe_kanban_card" >
<div t-attf-class= "Oe_kanban_card
#{kanban_color (Record.color.raw_value)} ">
# Add ellipses for long text
<t t-esc= "Kanban_text_ellipsis (Record.name.value, +)"/>
Over 32 characters plus ... The content is not displayed
# Custom CSS and JavaScript resources
<?xml version= "1.0" encoding= "Utf-8"?>
<openerp>
<data>
<template id= "Assets_backend"
Inherit_id= "Web.assets_backend"
Name= "Todo Kanban Assets" >
<xpath expr= "." Position= "Inside" >
<link rel= "stylesheet"
href= "/todo_kanban/static/src/css/todo_kanban.css"
/>
<script type= "Text/javascript"
src= "/todo_kanban/static/src/js/todo_kanban.js" >
</script>
</xpath>
</template>
</data>
</openerp>
* Create business Reports
Some of the qweb techniques learned above can be used on reports
Order first.
todo_kanban/__openerp__.py
---------------
' Data ': [' todo_view.xml ', ' todo_report.xml ']
---------------
Todo_report.xml
---------------
<?xml version= "1.0"?>
<openerp>
<data>
<report id= "Report_todo_task_action"
string= "To-do Tasks"
Model= "Todo.task"
Report_type= "Qweb-pdf"
Name= "Todo_kanban.report_todo_task_template"
/>
<template id= "Report_todo_task_template" >
<t t-call= "Report.html_container" >
<t t-foreach= "Docs" t-as= "O" >
<t t-call= "Report.external_layout" >
<div class= "Page" >
<!--report page content--
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>
<report> is a shortcut to the Ir.actions.report.xml model
Reports can be found in the report, technology-
T-call called the standard reporting schema, this is important
The report.external_layout contains the head and tail, or it can be used only with report.internal_layout
The head of the infrastructure, the rest of the writing itself
#注意, reports, use of wkhtmltopdf dependency
http://wkhtmltopdf.org/downloads.html wkhtmltopdf-0.12.1 Version
$ sudo apt-get remove--purge wkhtmltopdf
$ cd/tmp
$ wget HTTP://DOWNLOADS.SOURCEFORGE.NET/PROJECT/WKHTMLTOPDF/ARCHIVE/0.12.1/
Wkhtmltox-0.12.1_linux-trusty-adm64.deb
$ sudo dpkg-i wkhtmltox-0.12.1_linux-trusty-amd64.deb
#在报表中呈现数据
Available variables:
The docs loop prints out a recordset
Doc_ids The IDs list of a recordset is printed
Doc_model call which model to handle
Time
User of this execution report
Res_company the company where the current user is located
Field values can also be supplemented with the T-field property t-field-options
Last dish:
<H2 t-field= "O.name"/>
<p t-field= "O.user_id.name"/>
<ul>
<t t-foreach= "O.message_follower_ids" t-as= "F" >
<li>
t-att-src= "' data:image/png;base64,%s '% f.image_small"
Style= "MAX-HEIGHT:45PX;" />
<span t-field= "F.name"/>
</li>
</t>
</ul>
There are currency fields:
<span t-field= "O.amount"
T-field-options= ' {
"Widget": "Monetary",
"Display_currency": "o.pricelist_id.currency_id"} '/>
<div t-field= "res_company.partner_id"
T-field-options= ' {
"Widget": "Contact",
"Fields": ["Address", "name", "Phone", "fax"],
"No_marker": true} '/>
Support Language Translation
<template id= "Report_todo_task_template" >
<t t-call= "Report.html_container" >
<t t-foreach= "Doc_ids" t-as= "doc_id" >
<t t-raw= "Translate_doc (doc_id, Doc_model,
' User_id.partner_id.lang ',
' Todo_kanban.report_todo_task_doc ') "/>
</t>
</t>
</template>
Translate_doc
#设计报表内容
Serving
<template id= "Report_todo_task_doc" >
<t t-call= "Report.external_layout" >
<div class= "Page" >
<div class= "Row" >
<div class= "col-xs-12" >
<span t-field= "O.name"/>
</div>
</div>
<div class= "Row" >
<div class= "Col-xs-8" >
By:
<span t-field= "o.user_id"/>
</div>
<div class= "Col-xs-4" >
Deadline:
<span t-field= "O.date_deadline"/>
</div>
</div>
<!--Table--
<table class= "Table table-bordered" >
<!--Table Header--
<tr>
<th>Avatar</th>
<th>Name</th>
</tr>
<!--Table Rows--
<t t-foreach= "O.message_follower_ids" t-as= "F" >
<!--each row--
<tr>
<td>
t-att-src= "' data:image/png;base64,%s '% f.image_small"
Style= "MAX-HEIGHT:32PX;" />
</td>
<td>
<span t-field= "F.name"/>
</td>
</tr>
<!--Totals in a last row--
<t t-if= "F_last" >
<tr>
<TD colspan= "2" >
<strong>
<p class= "Text-right" >
<t t-esc= "Len (o.message_follower_ids)"/>
Followers
</p>
</strong>
</td>
</tr>
</t>
<!--End Table totals--
</t>
</table>
</div>
</t>
</template>
Note: Col-xs-n N represents how many columns are written as bootstrap, one row is divided into 12 columns
<t t-if= "F_last" > Loop to the end
#纸张格式
<record id= "report_todo_task_action" model= "Ir.actions.report.xml" >
<field name= "name" >to-do tasks</field>
<field name= "Model" >todo.task</field>
<field name= "Report_type" >qweb-html</field>
<field name= "Template_name" >
Todo_kanban.report_todo_task_template
</field>
<field name= "paper_format_id" ref= "Report.paperformat_euro"/>
</record>
PAPER_FORMAT_ID refers to the Report.paperformat_euro format, which can be
Paper format, reporting, technology---
Odoo Kanban views and reports