(04)odoo视图操作

-----------------
更新时间
19:04 2016-09-29 星期四
11:17 2016-09-18 星期日
18:13 2016-04-05 星期二
15:05 2016-03-14 星期一
11:46 2016-02-25 星期四
14:51 2016-02-23 星期二
18:07 2016-02-19 星期五
17:44 2016-02-17 星期三
-----------------
* 视图标签类型
    # <record>标签有属性 model="ir.ui.view" ,它包含本身的视图定义
    # <record>标签有属性 mo="ir.actions.act_window",它将动作和视图链接起来
    # <menuitem>标签,把菜单和动作链接起来

* 模板(Templating)
    <template id="..." name="...">
      html
    </template>
   
    --------
    <record id="..." model="ir.ui.view">
       <field name="name">...</field>
       ...
       <field name="arch" type="xml">
           html
       </field>
     </record>
    
    #渲染模板
        http.request.render(template[,values])
       
        @http.route('/hello/')
        def hello(self, **kw):
            return http.request.render(module.hello)
    -------
        <template id="hello">
            <p> hello , <t t-esc="name"/></p>
        </template>
    --------
        return http.request.render(module.hello,{'name':"World"}) # 带参数
       
    # Qweb 设置变量值
        <template id="hello">
            <t t-set="greet" t-value="name+'!!!'">
            <p> hello , <t t-esc="greet"/></p>
        </template>
    --------
        <template id="hello">
            <t t-set="greet" t-valuef="{ {name}}!!!">
            <p> hello , <t t-esc="greet"/></p>
        </template>
    ---------
     原样输出
        <template id="hello">
            <t t-set="greet">
                <em>Hello</em>, <t t-esc="name"/>
            </t>
            <p> hello , <t t-raw="greet"/></p>
        </template>
       
    # Qweb 语句
      条件语句
          <template id="hello">   
            <p>
                <span t-if="name=='World'" />
                    Hello World!
                </span>
            </p>
          </template>
          -----
          <template id="hello">   
            <t t-set="condition" t-value="name=='World'">
            <p>
                <span t-if="condition" />
                    Hello World!
                </span>
            </p>
            <p>
                <span t-if=" not condition" />
                    Hello not World!
                </span>
            </p>
          </template>
     
      循环语句
           <template id="hello">
                <ul>
                    <li t-foreach="name" t-as="letter">
                        <t t-esc="letter_index"/>:<t t-esc="letter" />
                    </li>
                </ul>
           <template>
           -------
           <t t-foreach="seq" t-as="value">
           * value 项值
           * value_size 大小
           * value_all 总数
           * value_index 索引号
           * value_first:bool 第一个
           * value_last:bool 最后一个
           * value_parity:'even'|'odd' 当前是第奇数还是偶数
      
       调用其它模板
           采用t-call
           <template id="sub">
            <t t-esc="identifier" />
           </template>
           <template id="hello">
            <p>
                hello,
                <t t-call="module.sub">
                    <t t-set="identifier" t-value="name" />
                </t>
            </p>
           </template>
      
       属性设置
           t-att-{attname}="{expression}"
           t-attf-{attname}="{expression}"
           ------
           <template id="hello">
            <p t-att-class="name.lower()">Hello,world</p>
            <p t-attf-class="cl-{ {name.lower()}}">Hello,world</p>
           <template>
      
       字段渲染
           @http.route('hello/<model("res.users"):user')  # 给用户的id即可
           def hello(self,user,**kw)
                return http.request.render('module.hello',{'user':user})
            -------
            <template id="hello">
                <p t-field="user.display_name" />
            </template>
       ---------
       可用字段选择修饰
           <template id="hello">
                <p t-field="user.creat_date" />
                <p t-field="user.creat_date"  t-filed-options='{"format":"long"}'/>
                <p t-field="user.creat_date"  t-filed-options='{"format":"EEE"}'/>
            </template>
            -------------
            <template id="hello">
                <p t-field="user.wealth" />
                <p t-field="user.wealth"  t-filed-options='{
                     "widget":"monetary"
                     "display_currency":"user.company_id.currency_id"
                     }'/>
            </template>
            ------------
            <template id="hello">
                <p t-field="user.create_date" t-field-options='{"widget":relative}}' />
            </template>
       
        模板继承
            <template id="hello">
                <p> Base template </p>
            </template>
            <template id="hello2" inherit_id="hello" name="Extender">
                <xpath expr="//p" position="before">
                    <h1>Extended!</h1>
                </xpath>   
            </template>
             得到的结果:
               <h1>Extended!</h1>
               <p>Base template</p>
            --------------
            <template id="hello">
                <p class="a">A</p>
                <p class="b">B</p>           
            </template>
            <template id="hello2" inherit_id="hello" name="Extender">
                <xpath expr="//p[hasclass('b')]" position="before">
                    <h1>Extended!</h1>
                </xpath>   
            </template>   
              得到的结果:
               <p class="a">A</p>
               <h1>Extended!</h1>
               <p class="b">B</p>
            ----------
            调用系统的基础模板:
              <template id="hello">
               <t t-call="website.layout">
                    <p class="a">A</p>
                    <p class="b">B</p>   
               </t>               
            </template>
            <template id="hello2" inherit_id="hello" name="Extender">
                <xpath expr="//p[hasclass('b')]" position="before">
                    <h1>Extended!</h1>
                </xpath>   
            </template>   
            -----------
                   
           
* 视图
    <record id="view_id" model="ir.ui.view">
       <field name="name">view.name</field>
       <field name="model">object_name</field>
       <field name="type">form</field>
       <field name="priority" eval="16" />
       <field name="arch" type="xml">
          <!-- view content <form>,<tree>,<graph>,.. -->
       </field>
   </record>   
   属性:
   openerp/addons/base/ir/ir_ui_view.py view类中的_columns
   model:固定为 ir.ui.view
   id 唯一,调用和继承会用到
   name 视图名称
   model 对象
   type 有多种类型 tree,form,graph,calendar,diagram,gantt,kanban,search
   priority  排序
  
* 视图继承(用于修改已有的视图):
   这里有一个小技巧:
   当你继承父视图,
   1.只添加字段时,本视图外id值可以和父视图id值 一样,这样后面再继承方便
   2.当要隐藏或删除父字段时,本视图外id不能和父视图id值一样,否则后面无法升级模块
  
    <record model="ir.ui.view" id="view_partner_form">
        <field name="name">res.partner.form.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" /> <!--声明要修改那一个视图-->
        <field name="arch" type="xml">
            <notebook position="inside">
                <page string="Relations">
                    <field name="relations_ids" colspan='4' nolabel="1" />
                </page>
            <notebook>
        <field>
    </record>
    所有的操作只能在
    <field name="arch" type="xml">... </field>
   
    定位5种属性
    @ inside(默认):附加在标签内
    @ after:后添加内容标签
    @ before:前的内容标签
    @ replace: 更换标签内容
    @ attributes: 更改标签内容的属性
   
   支持定位方法:
            <notebook position="inside">
            <xpath expr="//page[@name='page_history']" position="inside">
            <field name="mobile" position="after">
            <filter name="consumable" position="after" >
            <group name="bank" position="after">
            <xpath expr="//field[@name='standard_price']" position="replace">
            <xpath expr="//button[@name='open_ui']" position="replace">
            <xpath expr="//div[@class='oe_employee_details']/h4/a" position="after">
            <xpath expr="//form/sheet/notebook/page/field[@name='line_ids']/tree/field[@name='analytic_account_id']"
                    position="replace">
            <xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/form/group/field[@name='analytic_account_id']"
                    position="replace">   
    # 更换内容:
        <record model="ir.ui.view" id="view_partner_form1">
            <field name="name">res.partner.form.inherit1</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="arch" type="xml">
                    <page string="Extra Info" position="replace">
                        <field name="relations_ids" colspan='4' nolabel="1" />
                    </page>
            <field>
        </record>
   
    # 删

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值