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使用 设计目的是共享哪些对于组件来说全局的数据 不要因为仅仅为了避免在几个层级下的 ...
随机推荐
- 【NX二次开发】属性操作相关函数的使用方法
内容包括:1.属性创建2.判断属性是否存在3.读取属性值4.时间属性转换成字符串5.统计属性的数量6.删除指定属性7.删除全部属性效果: 源码: #include <stdlib.h> # ...
- 【NX二次开发】镜像对象
使用uf5946获取镜像矩阵注意:uf5946镜像这个函数,只能用#define UF_plane_type=46这种类型的数据作为镜像面,不能用#define UF_datum_plane_type ...
- 【NX二次开发】修改dlx对话框标题的方法
修改dlx名称, 修改对话框标题的方法: theDialog->TopBlock()->FindBlock("Dialog")->GetProperties()- ...
- js笔记4
1.js数据类型分析 (1)基础类型:string.number.boolean.null.undefined (2)引用类型:object-->json.array... 2.点运算 xxx ...
- 如何在Vue的项目里对element的表单验证进行封装
介绍需求 熟悉并优化公司项目的第五天,领导说能不能把表单验证封装一下,我打开代码一看 由于是后台管理系统,无数个需要验证的输入框,由于截图长度受限,只能展示部分,类似于这种页面还有无数个!代码重复率非 ...
- 流程自动化RPA,Power Automate Desktop系列 - 创建WPF程序安装包及升级包
一.背景 之前写过的几个WPF小工具,每次发布都需要给它打安装包和升级包,涉及到一些系列繁琐的手工操作,有了Power Automate Desktop,于是便寻思着能不能做成一个自动化的流来使用. ...
- Git&Gitlab开发流程与运维管理
Git&Gitlab开发流程与运维管理 作者 刘畅 时间 2020-10-31 实验系统版本centos7.5 主机名称 ip地址 配置 安装软件 controlnode 172.16.1.1 ...
- POJ 1269 Intersecting Lines 判断两直线关系
用的是初中学的方法 #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- 计算机、程序和java简介
内存 计算机的内存是由一个有序的字节序列组成,用于存储程序及程序需要的数据.你可以将内存想象成计算机执行程序的工作区域.一个程序和它的数据在被CPU执行前必须移到计算机的内存中. 每个字节都是有一个唯 ...
- 『动善时』JMeter基础 — 54、JMeter聚合报告详解
目录 1.聚合报告介绍 2.聚合报告界面详解 3.聚合报告中信息点说明 (1)百分位数的说明 (2)吞吐量说明 提示:聚合报告组件的使用和察看结果树组件的使用方式相同.本篇文章主要是详细的介绍一下聚合 ...