zoukankan      html  css  js  c++  java
  • (49) odoo context操作

    * context
      这是一个上下文,运用很灵活

    * 得到整个context
      V7
      context=dict(context or {})
      这个版本是明传
      V8
      self.context_get()
      self.env['res.users'].context_get()

    * 得到context里面对应的值

      得到flag的值
     
      V8
      self.env.context.get('flag',False)

      V7
      context.get('flag',False)

    * 修改context里面的对应的值

      V8
      self.with_context({'flag': False})
      或
      self.with_context(flag=True) 单一时
      或
      ctx = dict(context or {})
      ctx['flag']=False
      self.with_context(ctx)

      v7
      context = dict(context or {})
      这句不在改前一定要有,否则报错
      -------
      context.update({'flag': False})
      或:
      context.update(flag=True)单一时
      或:
      context['flag']=False

    * 保证context的字典类型
      context = dict(context or {})

    * 复制context
      c = context.copy()
      主要改变部分值,带到其它函数中

    * 自己构造context
      context = {'flag':Fasle,'lang':'zh_cn'}

    * 常规用法
      v7 带入函数中
          def create(self, cr, uid, vals, context=None):
            context = dict(context or {})

      v8 带入函数中
        if part.lang:
                self = self.with_context(lang=part.lang)
            product = self.env['product.product'].browse(product)
       ------
       return self.with_context(ctx).write({'invoice_line': []})
       记住,用了 with_context

    * 视图中引入context
      model="ir.actions.act_window"时
      <field name="context">{"search_default_my_export_list":1} </field>
      代表 搜索时 my_expert_list 值为1 对于 search_default_是系统的前置标识

      分组
      <filter string="Day"name="group_day"context="{'group_by':'date_start:day'}"

      指定搜索
      <field name="department_id" string="Department" context="{'invisible_department': False}"/>


      列表中字段
      <field name="line_ids" context="{'currency_id': currency_id,
       'default_analytic_account': context.get('analytic_account', '')}">

    视图定义context 带入函数
    <field name="product_id" on_change="onchange_product_id(product_id, context)"
      context="{'default_hr_expense_ok':1}"/>

    * context上面是常用的方法,掌握后,就可以在整个系统中方便传数值,但是上下文,不要传太多                               

  • 相关阅读:
    最大流问题的几种经典解法综述
    有上下界的网络流
    hiho一下
    poj 1018
    状压dp
    hdu 1043
    Poj1015
    7.14
    sgu 128
    (zhuan)
  • 原文地址:https://www.cnblogs.com/toby2chen/p/6141284.html
Copyright © 2011-2022 走看看