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使用 设计目的是共享哪些对于组件来说全局的数据 不要因为仅仅为了避免在几个层级下的 ...
随机推荐
- 『动善时』JMeter基础 — 43、JMeter对数据库的查询操作
目录 1.使用"用户自定义变量"实现参数化 2. 在SQL Query中使用占位符传递参数 (1)传递的参数值是常量 (2)传递的参数值是变量 3.Variables names参 ...
- Java协程实践指南(一)
一. 协程产生的背景 说起协程,大多数人的第一印象可能就是GoLang,这也是Go语言非常吸引人的地方之一,它内建的并发支持.Go语言并发体系的理论是C.A.R Hoare在1978年提出的CSP(C ...
- 二、Linux基本防护措施
修改账户有效期 chage命令的语法格式: chage –l 账户名称 //查看账户信息 chage –E 时间 账户名称 ...
- 与安卓联调,调用安卓那边的方法,获取到安卓传过来的数据,再携带这些数据发送axios请求,获取到用户的信息
第一步:js调用Android方法:接收Android传递过来的数据,并做处理 //参数一:调用java中的方法 submitFromWeb是方法名,必须和Android中注册时候的方法名称保持一 ...
- 彻底解决Spring mvc中时间类型的转换和序列化问题
在使用Spring mvc 进行开发时我们经常遇到前端传来的某种格式的时间字符串无法用java8时间包下的具体类型参数来直接接收.同时还有一系列的序列化 .反序列化问题,在返回前端带时间类型的同样会出 ...
- [.NET大牛之路 001] .NET 其名
本文来自『.NET大牛之路』星球的分享 大家好,这是 .NET 大牛这路的第 1 篇文章.大家期待已久的课程今天正式开始了.既然我们整个体系课程都将围绕 .NET 展开,那我们今天就先聊一聊 .NET ...
- 创建react项目并集成eslint/prettier/commit-lint
创建 react 项目 npx create-react-app jira-new --template typescript 如果不想使用 TS,而要用 JS 的话,则删除 -template ty ...
- Fiddler手机抓包配置指南
前言: 对于开发.测试而言,抓包工具绝对是我们日常测试找bug的必备神器.今天主要介绍的是如何配置Fiddler抓取移动端app请求.首先Fiddler是一个http协议调试代理工具,它能够记录并检查 ...
- Linux常用命令详解下
Linux常用命令详解 目录 一.Linux常用命令 1.1.查看及切换目录(pwd.cd.ls.du) 1.2.创建目录和文件(mkdir.touch.ln) 1.3.复制.删除.移动目录和文件(c ...
- 流程自动化RPA,Power Automate Desktop系列 - 发布文档中心
一.背景 内网中有一个基于VuePress搭建的静态文档中心,但是每次修改后都需要重新Build一次才行,之前都是手动执行命令,现在可以基于Power Automate Desktop来创建任务了. ...