odoo里面context用法
原文转自: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用法的更多相关文章
- odoo 开发 context 上下文的用法
context 这是一个上下文,运用很灵活 得到整个context self.context_get() self.env['res.users'].context_get() 得到cont ...
- webpack中require.context 用法
1.require.context(directory, useSubdirectories = false, regExp = /^\.\//) Examples: require.context( ...
- (48) odoo的button用法
button 应用的比较多,这里来汇总一下 按钮<button>,支持的属性 icon 可用的icon在 addons/web/static/src/img/icons ...
- 引用reference作用域scope闭包closure上下文context用法
引用(reference).作用域(scope).闭包(closure)以及上下文(context)是JavaScript重中之重的基础,也是学习好JavaScript的基础.在这里我以浅显的理解给大 ...
- odoo t标签用法
在odoo中,通过QWeb来对模板进行渲染后加载到浏览器中,而模板中有许多的标签来定制各种需求变化,在这里记录学习过程中碰到的标签定义,以方便查询. 模板中的标签统一都是以"t-" ...
- golang context用法详解
背景 在go服务器中,对于每个请求的request都是在单独的goroutine中进行的,处理一个request也可能设计多个goroutine之间的交互, 使用context可以使开发者方便的在这些 ...
- odoo 装饰器用法@api
摘自:blog.csdn.net/cmzhuang/article/details/52932883 @api.one one装饰符自动遍历记录集,把self重新定义成当前记录.注意,返回值是一个li ...
- 【转】Appium_API(翻译+用法说明)
转自:https://testerhome.com/topics/3711 1.contextscontexts(self): Returns the contexts within the curr ...
- react之context
context是什么 Props属性是由上到下单向传递的 context提供了在组件中共享此类值的方法 context使用 设计目的是共享哪些对于组件来说全局的数据 不要因为仅仅为了避免在几个层级下的 ...
随机推荐
- 03:进程Queue --- 生产者消费者模型
1 进程Queue介绍 1 进程间数据隔离,两个进程进行通信,借助于Queue2 进程间通信:IPC -借助于Queue实现进程间通信 -借助于文件 -借助于数据库 -借助 ...
- 学习响应式编程 Reactor (3) - reactor 基础
Reactor Reactor 项目的主要 artifact 是 reactor-core,这是一个基于 Java 8 的实现了响应式流规范的响应式库. Reactor 提供了实现 Publisher ...
- NTLM协议与Pass the Hash的爱情
0x01.前言 NTLM使用在Windows NT和Windows 2000 Server或者之后的工作组环境中(Kerberos用在域模式下).在AD域环境中,如果需要认证Windows NT系统, ...
- Excel对单元格设置上涨、下降箭头
1.有以下学生成绩表,对期末考试设置上涨.下降箭头,体现考生成绩变动: 2.选中C2,"条件格式"-"管理规则"-"新建规则"-" ...
- 11、函数(def)
11.1.函数: 函数即变量 函数的作用域只跟函数声明时定义的作用域有关,跟函数的调用位置无任何关系 1.函数格式: def test(x): ''' 2*x+1 :param x:整形数字 :ret ...
- 教你几招HASH表查找的方法
摘要:根据设定的哈希函数 H(key) 和所选中的处理冲突的方法,将一组关键字映象到一个有限的.地址连续的地址集 (区间) 上,并以关键字在地址集中的"象"作为相应记录在表中的存储 ...
- 『心善渊』Selenium3.0基础 — 19、使用Selenium操作文件的上传和下载
目录 1.Selenium实现文件上传 (1)页面中的文件上传说明 (2)文件上传示例 (3)总结 2.Selenium实现文件下载 (1)Firefox浏览器文件下载 1)操作步骤: 2)文件下载示 ...
- 【知识点】C++的日志框架
常用的 C++ 日志框架 一.日志框架 一个经过专门设计的实用程序,用于规范应用程序的日志记录过程,就是日志框架. 日志框架可以自己编写(需要一定的能力哦),也可以由第三方(例如:log4cplu ...
- Java运算中的类型转换
类型转换 运算中,不同类型的数据先转化为同一类型,然后进行运算 public class Dome04 { public static void main(String[] args) { //int ...
- RabbitMQ 常用知识点总结
基础 为什么使用 MQ? 1.削峰:在某个模块接收到超过最大承受的并发量时,可以通过 MQ 排队来使这些削减同一时刻处理的消息量.减小并发量. 2.解耦:在发送 MQ 处理业务时,可以使业务代码与当前 ...