Odoo Documentation : Environment
Environment
The Environment stores various contextual data(上下文数据 ) used by the ORM: the database cursor (for database queries), the current user (for access rights checking) and the current context (storing arbitrary metadata). The environment also stores caches.
All recordsets have an environment, which is immutable(不可改变的), can be accessed using env and gives access to the current user (user), the cursor (cr) or the context (context):
>>> records.env
<Environment object ...>
>>> records.env.user
res.user(3)
>>> records.env.cr
<Cursor object ...)
When creating a recordset from an other recordset, the environment is inherited. The environment can be used to get an empty recordset in an other model, and query that model:
>>> self.env['res.partner']
res.partner
>>> self.env['res.partner'].search([['is_company', '=', True], ['customer', '=', True]])
res.partner(7, 18, 12, 14, 17, 19, 8, 31, 26, 16, 13, 20, 30, 22, 29, 15, 23, 28, 74)
Altering the environment
The environment can be customized from a recordset. This returns a new version of the recordset using the altered environment.
sudo()-
creates a new environment with the provided user set, uses the administrator if none is provided (to bypass access rights/rules in safe contexts), returns a copy of the recordset it is called on using the new environment:
# create partner object as administrator
env['res.partner'].sudo().create({'name': "A Partner"}) # list partners visible by the "public" user
public = env.ref('base.public_user')
env['res.partner'].sudo(public).search([]) with_context()-
- can take a single positional parameter, which replaces the current environment's context
- can take any number of parameters by keyword, which are added to either the current environment's context or the context set during step 1
# look for partner, or create one with specified timezone if none is
# found
env['res.partner'].with_context(tz=a_tz).find_or_create(email_address) with_env()- replaces the existing environment entirely
Odoo Documentation : Environment的更多相关文章
- Odoo Documentation : Fields
Fields Basic fields class openerp.fields.Field(string=None, **kwargs) The field descriptor contains ...
- Odoo Documentation : Recordsets
Other recordset operations Recordsets are iterable(可迭代的) so the usual Python tools are available for ...
- Odoo Shell
Odoo shell 提供了一个简便的操作 Odoo的交互界面, 从 odoo 9.0 开始就是标准功能, 无需安装第三方应用. 本文基于Odoo10 说明 Odoo Shell以及 Odoo Mod ...
- Defining custom settings in Odoo
Unfortunately Odoo documentation doesn’t seem to include any information about adding new configurat ...
- Implementation Documentation[转]
原文地址:http://prasanna-adf.blogspot.tw/2009/04/implementation-documentation.html Following are the lis ...
- odoo配置界面设置字段默认值
转自国外牛人博客:http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html Defining custom settings in O ...
- odoo 有哪些文档资源
// openbook [覆盖 openerp 7 及之前版本] https://doc.odoo.com/ // 最新的 odoo documentation user[覆盖 odoo 9] ...
- 第七章 Odoo 12开发之记录集 - 使用模型数据
在上一篇文章中,我们概览了模型创建以及如何从模型中载入和导出数据.现在我们已有数据模型和相关数据,是时候学习如何编程与其进行交互 了.模型的 ORM(Object-Relational Mapping ...
- linux命令总结之date命令
命令简介: date 根据给定格式显示日期或设置系统日期时间.print or set the system date and time 指令所在路径:/bin/date 命令语法: date [OP ...
随机推荐
- 十二. for of 示例 (可以解决大多数应用场景)
for of entries() 可以同时拿到数组的索引跟值 因此可以使用解构的语法: for of 示例 1. 求和 2.字符串
- leetcode-227-基本计算器②
题目描述: 方法一:中缀转后缀 #!_*_coding:utf-8_*_ class Solution: def calculate(self, s: str) -> int: def in_t ...
- 校园商铺-4店铺注册功能模块-1Dao层之更新店铺
dao层增加更新店铺的方法 package com.csj2018.o2o.dao; import com.csj2018.o2o.entity.Shop; public interface Shop ...
- 廖雪峰Java16函数式编程-2Stream-4map
1. map()简介 Stream.map()是一个Stream的转换方法,把一个stream转换为另一个Stream,这2个Stream是按照映射函数一一对应的. 所谓map操作,就是把一种操作运算 ...
- PHP跨服务器提交数据
关于类似的问题,百度上一搜一大堆,这只是我自己实际用过的两个方法,不多BB直接上代码 1.第一种: 2.第二种 可以随意切换POST和GET提交方式
- Linux的命令提示符 修改
Linux的命令提示符可按个人喜好随意更改,修改PS1的值即可: 在Ubuntu下若只是个别用户下修改~/.profile文件就好,所有用户统一则修改/etc/profile: 加入: export ...
- (转)[视频压制/转换技术] I帧 B帧 P帧 IDR帧 等帧用途详细说明
转:http://www.u2game.net/bbs/thread-46116-1-1.html 在视频压制.转换中,经常会看到:I帧 B帧 P帧 IDR帧 等名词,这里就是通用的解释一下这些帧的用 ...
- 1 A+B问题
原题网址: http://www.lintcode.com/zh-cn/problem/a-b-problem/# 给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符. 注意事项 你不需 ...
- 可拖拽排序的vue组件
最近在优化一个vue的博客系统,想实现文章列表处的文章拖拽功能.就试了一下awe-dnd vue插件,觉得还挺好用的. 安装 npm install awe-dnd --save 使用 在main.j ...
- 洛谷P1792——[国家集训队]种树
传送门:QAQQAQ 题意:$n$个点中选$m$个不相邻的点,使得这些点不相邻(1和n算相邻),求这些点的最大值 思路:这不是神仙题不是神仙题…… 刚看到这题觉得不难,好像只要贪心就可以了但贪心不知从 ...