首页 > 其他 > 详细

odoo - context

时间:2018-10-24 13:32:45      阅读:212      评论:0      收藏:0      [点我收藏+]

 得到整个context

  self.context_get()
  self.env[res.users].context_get()

得到context里面对应的值

    eg:得到flag的值

 self.env.context.get(flag,False)

修改context里面的对应的值

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

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

复制context

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

自己构造context

  context = {flag:Fasle,lang:zh_cn}

常规用法
  带入函数中

    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}"/>

many2one字段指定打开视图:

tree_view_ref,form_view_ref,……
<field name="stock_quant_id" required="1" options="{‘no_create_edit‘: True}" context="{‘tree_view_ref‘:‘tjc_stock.tjc_view_stock_quant_tree‘}"/>

 

odoo - context

原文:https://www.cnblogs.com/yifugui/p/9842907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!