原文转自:https://www.cnblogs.com/zhaoweihang/p/9698852.html

<field name="partner_id" string="Customer"
widget="res_partner_many2one"
context="{'default_name': contact_name, 'default_street': street, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_function': function, 'default_phone': phone, 'default_mobile': mobile, 'default_email': email_from, 'default_user_id': user_id, 'default_team_id': team_id, 'default_website': website, 'show_vat': True}"
groups="base.group_no_one"/>

context   这是一个上下文,运用很灵活  得到整个context   self.context_get()

self.env['res.users'].context_get() 得到context里面对应的值 得到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"时   {"search_default_my_export_list":1}

代表 搜索时 my_expert_list 值为1 对于 search_default_是系统的前置标识

设置值:获取表单中的字段:【字段1、字段2】

     self.with_context({'字段1': 'aaaaaa','字段2': 'bbbaaa'})

获取值:

self._context.get('字段1')

案例00001:

@api.multi
def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False):
""" Low-level method - Mono pricelist, multi products
Returns: dict{product_id: (price, suitable_rule) for the given pricelist}

If date in context: Date of the pricelist (%Y-%m-%d)

:param products_qty_partner: list of typles products, quantity, partner
:param datetime date: validity date
:param ID uom_id: intermediate unit of measure
"""
self.ensure_one()
if not date:
date = self._context.get('date') or fields.Date.context_today(self)
if not uom_id and self._context.get('uom'):
uom_id = self._context['uom']
if uom_id:
# rebrowse with uom if given
products = [item[0].with_context(uom=uom_id) for item in products_qty_partner]
products_qty_partner = [(products[index], data_struct[1], data_struct[2]) for index, data_struct in enumerate(products_qty_partner)]
else:
products = [item[0] for item in products_qty_partner]

if not products:
return {}

案例00002

odoo里面context用法的更多相关文章

  1. odoo 开发 context 上下文的用法

    context   这是一个上下文,运用很灵活  得到整个context   self.context_get() self.env['res.users'].context_get() 得到cont ...

  2. webpack中require.context 用法

    1.require.context(directory, useSubdirectories = false, regExp = /^\.\//) Examples: require.context( ...

  3. (48) odoo的button用法

    button 应用的比较多,这里来汇总一下 按钮<button>,支持的属性     icon  可用的icon在 addons/web/static/src/img/icons     ...

  4. 引用reference作用域scope闭包closure上下文context用法

    引用(reference).作用域(scope).闭包(closure)以及上下文(context)是JavaScript重中之重的基础,也是学习好JavaScript的基础.在这里我以浅显的理解给大 ...

  5. odoo t标签用法

    在odoo中,通过QWeb来对模板进行渲染后加载到浏览器中,而模板中有许多的标签来定制各种需求变化,在这里记录学习过程中碰到的标签定义,以方便查询. 模板中的标签统一都是以"t-" ...

  6. golang context用法详解

    背景 在go服务器中,对于每个请求的request都是在单独的goroutine中进行的,处理一个request也可能设计多个goroutine之间的交互, 使用context可以使开发者方便的在这些 ...

  7. odoo 装饰器用法@api

    摘自:blog.csdn.net/cmzhuang/article/details/52932883 @api.one one装饰符自动遍历记录集,把self重新定义成当前记录.注意,返回值是一个li ...

  8. 【转】Appium_API(翻译+用法说明)

    转自:https://testerhome.com/topics/3711 1.contextscontexts(self): Returns the contexts within the curr ...

  9. react之context

    context是什么 Props属性是由上到下单向传递的 context提供了在组件中共享此类值的方法 context使用 设计目的是共享哪些对于组件来说全局的数据 不要因为仅仅为了避免在几个层级下的 ...

随机推荐

  1. UF_UI 界面相关

    Open C   uc1600uc1601uc1603  uc1605uc1607uc1608uc1609uc1613  获取用户输入的字符串uc1615uc1616uc1617uc1618uc163 ...

  2. Spring MVC 到 Spring BOOT 的简化之路

    背景 Spring vs Spring MVC vs Spring Boot Spring FrameWork Spring 还能解决什么问题 Spring MVC 为什么需要Spring Boot ...

  3. 【模拟8.11】星空(差分转化,状压DP,最短路)

    一道很好的题,综合很多知识点. 首先复习差分:      将原来的每个点a[i]转化为b[i]=a[i]^a[i+1],(如果是求和形式就是b[i]=a[i+1]-a[i]) 我们发现这样的方便在于我 ...

  4. SprignBoot是如何访问工程目录下的静态资源?

    ​ 目录 1.牛刀小试 1.1 图片静态资源的访问 1.2 为静态资源添加访问前缀 1.3  WelCome Page 的奇妙跳转 2.那么,SpringBoot是如何做到的呢? ​​​​​​​ 1. ...

  5. 有趣的开源项目集结完毕,HelloGitHub 月刊第 63 期发布啦!

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 这里有实战项目.入门教程.黑科技.开源书籍.大厂开源项目等,涵盖多种编程语言 Pyt ...

  6. etcd 添加用户,授权特定目录

    适用场景 多组共用etcd集群,创建一个新用户.新目录,让这个新用户只有新目录的使用权限. 命令和顺序 创建目录,注意此处是v2 curl -u root:pwd http://host:2379/v ...

  7. 密码学系列之:twofish对称密钥分组算法

    简介 之前的文章我们讲到blowfish算法因为每次加密的块比较小只有64bits,所以不建议使用blowfish加密超过4G的文件.同时因为加密块小还会导致生日攻击等.所以才有了blowfish的继 ...

  8. 快速简单的了解VLAN(VXLAN)和端口链路类型

    目录 前言 一.VLAN是什么? 1.优点 2.为什么推出VXLAN 二.VXLAN又是什么? 1.优点 三.创建VLAN 四.介绍端口链路类型 五.Access 1.特性 六.Trunk 1.特性 ...

  9. excel自动记录项目完成进度,是否逾期,逾期/提前完成天数,计算天数可以把now()改为today()

    =IF(D38="",NOW()-C38,F38) 注:如果没有启用迭代计算,可以点击"文件"-"选项"-"公式"-&q ...

  10. 10、pfile和spfile文件详解

    10.1.介绍: 1.Oracle中的参数文件是一个包含一系列参数以及参数对应值的操作系统文件.它们是在数据库实例启动时候加载的, 决定了数据库的物理结构.内存.数据库的限制及系统大量的默认值.数据库 ...