openerp学习笔记 视图样式(表格行颜色、按钮,字段只读、隐藏,按钮状态、类型、图标、权限,group边距,聚合[合计、平均],样式)

时间:2023-02-21 16:22:44

表格行颜色:

            <tree string="请假单列表" colors="red:state == 'refuse';blue:state == 'draft';black:state in ('confirm','validate')">
            <tree string="Meeting" colors="gray:state in ('cancel','done');blue:state in ('pending',)">

表格行按钮:

            <button string="Meeting" states="open,pending" name="action_make_meeting" icon="gtk-redo" type="object"/>
            <button string="Convert to Opportunity" type="object" name="action_button_convert2opportunity" states="open,pending" icon="gtk-index" attrs="{'invisible':[('opportunity_id','!=',False)]}"/>

            <button name="case_open" string="Confirm" type="object" states="draft,pending" icon="gtk-go-forward"/>
            <button name="case_close" string="Held" type="object" states="open,pending" icon="gtk-jump-to"/>
            <button name="case_cancel" string="Cancel" type="object" states="draft,open,pending" icon="gtk-cancel"/>
            <button name="case_reset" string="Reset to Todo" type="object" states="cancel" icon="gtk-convert"/>

字段只读、隐藏:
            <field name="refuse_notes" attrs="{'readonly':[('state','!=','confirm'),('state','!=','validate')], 'invisible':[('state','!=','confirm'),('state','!=','validate'),('state','!=','refuse')]}"/>

按钮状态、类型、图标、权限:

            <button string="送批" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
            <button string="批准" name="validate" states="confirm" invisible="context.get('btn_validate_invisible', False)" type="workflow" icon="gtk-apply" groups="kl_qingjd.group_kl_qingjd_manager"/>
            <button string="拒绝" name="refuse" states="confirm,validate" invisible="context.get('btn_validate_invisible', False)" type="workflow" icon="gtk-no" groups="kl_qingjd.group_kl_qingjd_manager"/>
            <button string="还原为草稿" name="set_to_draft" states="cancel,refuse" type="object" icon="gtk-convert"/>

状态条颜色:(暂未生效)

            <field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate" statusbar_colors='{"confirm":"blue","validate":"blue","refuse":"red"}'/>

group边距设置为0:

<header>

                        <style>
                        .openerp .oe_form .oe_form_group {margin: 0}
                        </style>
                    </header>

分组后取合计数:

        <field name="days" string="天数" sum="合计"/>

分组后取平均数:

  字段定义:'probability': fields.float('Success Rate (%)',group_operator="avg"),

  表单录入:<field name="probability" class="oe_inline" widget="integer"/>%%

  分组后取平均数:<field name="probability" avg="Avg. of Probability"/>

  说明:暂时无法解决分组后平均数不是简单的按记录平均,而是根据字段的合计值重新计算获得的情况,如:利润率 = 利润金额合计/销售金额合计 的情况。

支持的分组聚合包括 sum,avg,max,min 等,除了 sum 可以直接在视图的字段中定义,别的操作必须在对象的字段中定义一下 group_operator,当视图与对象中定义不一致时,视图的优先级更高。

字段样式:

                        <h3>
                            <label string="派工单"/>
                            <field name="name" class="oe_inline" readonly="1"/>
                        </h3>

                            <field name="name" nolabel="1" readonly="1"/>

注意:给按钮设置权限组时,权限组ID必须包含所属模块前缀
         定义对象中的字段时,设置字段的属性 select=True 代表在表中为字段创建索引,在视图中设置字段的属性 select="1" 的用途暂时未知

示例代码:

<!-- views kl_qingjd_form -->
        <record
id="kl_qingjd_form"
model="ir.ui.view">
           
<field
name="name">kl.qingjd.form</field>
           
<field
name="model">kl.qingjd</field>
           
<field
name="type">form</field>
           
<field
name="priority">3</field>
           
<field name="arch"
type="xml">
               
<form string="请假单明细"
version="7.0">
                   
<header>
                       
<button string="送批" name="confirm" states="draft" type="workflow"
icon="gtk-yes"/
>
                       
<button string="批准" name="validate" states="confirm"
invisible="context.get('btn_validate_invisible', False)"
type="workflow" icon="gtk-apply"
groups="kl_qingjd.group_kl_qingjd_manager"/>
                       
<button string="拒绝" name="refuse" states="confirm,validate"
invisible="context.get('btn_validate_invisible', False)" type="workflow"
icon="gtk-no"
groups="kl_qingjd.group_kl_qingjd_manager"/>
                       
<button string="还原为草稿" name="set_to_draft"
states="cancel,refuse" type="object"
icon="gtk-convert"/>
                       
<field name="state" widget="statusbar"
statusbar_visible="draft,confirm,validate"
statusbar_colors='{"confirm":"blue","validate":"blue","refuse":"red"}'/>
                   
</header>
                   
<sheet>
                       
<group>
                           
<field name="employee_id" required="1"
on_change="onchange_employee(employee_id)"
attrs="{'readonly':[('state','!=','draft')]}"/>
                           
<field name="department_id"
attrs="{'readonly':[('state','!=','draft')]}"/>
                       
</group>
                       
<group>
                           
<field name="date_from" on_change="onchange_date_from(date_to, date_from)"
required="1"
attrs="{'readonly':[('state','!=','draft')]}"/>
                           
<field name="date_to" on_change="onchange_date_to(date_to, date_from)"
required="1"
attrs="{'readonly':[('state','!=','draft')]}"/>
                           
<field name="days" required="1"
attrs="{'readonly':[('state','!=','draft')]}"/>
                       
</group>
                       
<group>
                           
<field name="type_id" required="1"
attrs="{'readonly':[('state','!=','draft')]}"/>
                           
<field name="notes"
attrs="{'readonly':[('state','!=','draft')]}"/>
                       
</group>
                       
<group>
                           
<field name="refuse_notes"
attrs="{'readonly':[('state','!=','confirm'),('state','!=','validate')],
'invisible':[('state','!=','confirm'),('state','!=','validate'),('state','!=','refuse')]}"/
>
                       
</group>
                   
</sheet>
               
</form>
           
</field>
        </record>

<!-- views kl_qingjd_tree -->
  <record
id="kl_qingjd_tree" model="ir.ui.view">
   <field
name="name">kl.qingjd.tree</field>
   <field
name="model">kl.qingjd</field>
   <field
name="type">tree</field>
   <field
name="priority">2</field>
   <field name="arch"
type="xml">
    <tree string="请假单列表"
colors="red:state == 'refuse';blue:state == 'draft';black:state in
('confirm','validate')">
     <field
name="employee_id" select="1"/>
     <field
name="type_id" select="1"/>
     <field
name="days" string="天数"
sum="合计"/>
     <field
name="date_from" select="1"/>
     <field
name="date_to" select="1"/>
     <field
name="department_id" select="1"/>
     <field
name="notes" />
     <field name="state"
select="1"/>
     <field name="manager_id"
select="1"/>
     <field
name="create_uid" select="1"/> <!-- 此处需要读取创建者ID时,必须在对象中包含create_uid列
-->
    </tree>
   </field>
  </record>

<record model="ir.ui.view"
id="dispatch_work_order_form">
           
<field
name="name">dispatch.work_order.form</field>
           
<field
name="model">dispatch.work_order</field>
           
<field
name="type">form</field>
           
<field name="arch"
type="xml">
               
<form string="工单"
version="7.0">
                   
<header>
                   
 
                       
<button name="dispatch_work_order_deal" string="派工" states="draft" 
icon="gtk-yes"/>
                       
<button name="dispatch_work_order_done" string="报工" states="dealing"
icon="gtk-apply"
/>
                       
<button name="dispatch_work_order_reply" string="交单" states="done"
icon="gtk-convert"
/>
                       
<button name="dispatch_work_order_visit" string="回访" states="reply"
icon="gtk-apply" />

<field name="state" widget="statusbar" nolabel="1"
statusbar_visible="draft,dealing,done,reply,visit" 
statusbar_colors='{"draft":"blue","dealing":"blue","reply":"blue"}'/>
                       
<style>
                       
.openerp .oe_form .oe_form_group {margin: 0}
                       
</style>
                   
</header>
                   
<sheet>
                       
<h3>
                           
<label
string="派工单"/>
                           
<field name="name" class="oe_inline"
readonly="1"/>
                       
</h3>
                       
<group
col="2">
                           
<group col="4"
colspan="4">
                               
<field name="customer" on_change="on_change_customer(customer)" 
attrs="{'readonly':[('state','!=','draft')]}"/>
                               
<field
name="mobile"/>
                               
<field
name="phone"/>
                               
<field
name="buy_date"/>
                           
</group>
                           
<group col="6"
colspan="6">
                               
<field name="area" 
on_change="on_change_area(area)"/>
                               
<field
name="workload"/>
                               
<field
name="travelling_expenses"/>
                           
</group>
                           
<group col="2"
colspan="2">
                               
<field
name="address"/>
                           
</group>
                       
</group>
                   
<group
col="2">
                           
<group col="4"
colspan="4">
                      
<field
name="brand"/>
                
<field
name="series_number"/>
                           
</group>
                   
</group>
                   
<group
col="2">
                    
<field
name="description_of_fault"/>
                    
<field
name="note"/>
                   
</group>
                   
<group
col="2">
                           
<group col="6"
colspan="6">
                      
<field
name="client_source"/>
                      
<field
name="warranty_type"/>
                      
<field
name="buy_address"/>
                      
<field
name="appointment_date"/>
                      
<field
name="appointment_time"/>
                      
<field
name="repair_method"/>
                   
  </group>
                   
</group>

<group
col="2">
                           
<group col="4"
colspan="4">
                      
<field name="engineer"
on_change="on_change_engineer(engineer)"/>
                      
<field name="department"
readonly="True"/>
                   
  </group>
                           
<group col="2"
colspan="2">
                      
<field
name="check_result"/>
                      
<field
name="measure"/>
                   
  </group>
                           
<group col="6"
colspan="6">
                      
<field
name="service_time_1"/>
                      
<field
name="service_time_2"/>
                      
<field
name="amount"/>
                               
<field name="service_card" on_change="on_change_service_card(service_card)"
domain="[('state','=','1'),('customer','=',customer)]"
context="{'search_default_state1':1,
'search_default_customer':customer}"/>
                               
<field
name="service_card_remaining_times"/>
                               
<field
name="state_use_card"/>
                   
  </group>
                           
<group col="4"
colspan="4">
                      
<field
name="evaluate"/>
                      
<field
name="visit_time"/>
                   
  </group>
                           
<group col="2"
colspan="2">
                   
   <field
name="customer_feedback"/>
                   
  </group>
                   
</group>
                   
</sheet>

</form>
           
</field>
        </record>