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 ...
随机推荐
- 安装xampp之后报错XAMPP: Starting Apache...fail.
1.安装完成xampp之后报错: 2.网上查到的解决办法是:输入sudo apachectl stop 之后再次启动lampp,问题得以解决: 过两天发现问题并没有解决: ①在网上查询发现是因为端口被 ...
- 【JZOJ5431】序列操作
description 一开始有n个非负整数hi,接下来会进行m次操作,第i次操作给出一个数c[i],要求你选出c[i]个大于零的数并将它们减去1. 问最多可以进行多少轮操作后无法操作(即没有c[i] ...
- 【JZOJ6288】旋转子段
description analysis 可以先用前缀和把原串不调整的方案数先求出来 对于一种翻转,肯定是把\([i..a[i]]\)或\([a[i]..i]\)这段区间翻转 也可以看做是以\({i+ ...
- SQL Server 添加数据库没有权限等
{ 在安装好sql 后 第一次需要用windows 方式登陆 1.创建一个宁外一个登陆名登陆 在安全->登陆名 2.给此登陆属性的服务器角色添加sysadmin权限 //尽情享受!!! }
- thinkphp ASSIGN标签
ASSIGN标签用于在模板文件中赋值变量,用法如下: 直线电机厂家 <assign name="var" value="123" /> 在运行模板的 ...
- 16.ajax_case09
import requests import json import re from selenium import webdriver from selenium.webdriver.common. ...
- 4_7.springboot2.x嵌入式servlet容器自动配置原理
概述 Spring Boot对所支持的Servlet Web服务器实现做了建模抽象: Servlet容器类型 WebServer模型接口 WebServer工厂实现类 Tomcat Tomca ...
- java_网络编程之上传文件案例
初期成果: 客户端: package FileUpload; import java.io.*; import java.net.Socket; import java.util.Scanner; p ...
- Lotus Blossom 行动分析
1 漏洞介绍 1.1 代号 - Lotus Blossom行动 漏洞利用率很高 从2012 -2015或者说最近都还在使用 CVE-2012-0158 Lotus Blossom--莲花: 描述了对东 ...
- 【特别篇】NOIP2017划水记
本文是在精分状态下写的.. 逻辑混乱.. 记忆模糊.. 如果有不符合事实的地方欢迎各位当事人拿出证据指正.. 可能会很啰嗦 很矫情 很zz 不过不要对本蒟蒻进行人身攻击 武力威胁 他还是个宝宝(大雾) ...