Odoo 8.0 new API 之Environment

""" An environment wraps data for ORM records:

         - :attr:`cr`, the current database cursor;
         - :attr:`uid`, the current user id;
          - :attr:`context`, the current context dictionary.

        It also provides access to the registry, a cache for records, and a data
        structure to manage recomputations.
     """

Environment类提供了对ORM对象的封装,同时提供了对注册类的访问,记录集的缓存,以及管理重计算的数据结构.

对于继承了Model的类来说可以直接通过self.env对Environment进行操作.

属性列表:

1.user:返回当前用户 

self.env.user

2.lang:返回当前语言代码

self.env.lang

3.in_draft:返回是否处于草稿模式

self.env.in_draft

4.in_onchange:返回是否处于‘onchange‘草稿模式

self.env.in_onchange

另外还有cr,registery,cache,prefetch,computed,dirty,todo,mode,all等属性

应用说明:

1.利用env[model]获取类对象:

self.env[‘ir.model‘].search([(‘state‘, ‘!=‘, ‘manual‘)])

2.利用cr执行sql语句:

self.env.cr.execute(query, (value,))
时间: 2024-08-07 17:21:06

Odoo 8.0 new API 之Environment的相关文章

Odoo 8.0 new API 概述

相对于7来说,8的api改进了不少,用官方的话来说就是更加面向对象了. 下面探究一下具体的改动. 准备知识:python装饰器的使用 http://blog.csdn.net/thy38/article/details/4471421 在8中,api接口分为traditaional style和record style,traditional style指的就是我们在7中使用的类型,def (cr,uid,ids,context)式的语法.而record style精简了参数,只保留了self和

Odoo 8.0 new API 之constrains装饰

constrains装饰用于对字段进行限制 应用举例: 定义列: age = fields.Integer(string="age") 方法: @api.constrains('age') def _check_age(self): if self.age<16: raise ValueError(_('Age must be older than 16')) Odoo 8.0 new API 之constrains装饰

Odoo 8.0 new API 之one装饰

one装饰器的作用是对每一条记录都执行对应的方法,相当于traditional-style中的function 应用举例: 定义的columns now = fields.Datetime(compute='_compute_now') 方法: @one def _compute_now(self): self.now = fields.Datetime.now() Odoo 8.0 new API 之one装饰

Odoo 8.0 new API 之model 装饰

model装饰器的作用是返回一个集合列表 应用举例: 定义columns langs = fields.Selection(string="Lang",selection="_get_lang") 方法定义: @api.model def _get_lang(self): langs = self.env['res.lang'].search([]) return [(lang.code,lang.name) for lang in langs] Odoo 8.0

从头编写 asp.net core 2.0 web api 基础框架 (4) EF配置

原文:从头编写 asp.net core 2.0 web api 基础框架 (4) EF配置 第1部分:http://www.cnblogs.com/cgzl/p/7637250.html 第2部分:http://www.cnblogs.com/cgzl/p/7640077.html 第3部分:http://www.cnblogs.com/cgzl/p/7652413.html Github源码地址:https://github.com/solenovex/Building-asp.net-co

OAuth2.0学习(5-4)新浪开放平台-微博API-使用OAuth2.0调用API

使用OAuth2.0调用API 使用OAuth2.0调用API接口有两种方式: 1. 直接使用参数,传递参数名为 access_token URL 1 https://api.weibo.com/2/statuses/public_timeline.json?access_token=abcd 2.在header里传递,形式为在header里添加 Authorization:OAuth2空格abcd,这里的abcd假定为Access Token的值,其它接口参数正常传递即可. 注:所有的微博开放

配置ubuntu 14.04.3 LTS odoo 9.0开发环境

使用VMware Fusion 8.0.1创建ubuntu 64bit虚拟机:使用ubuntu-14.04.3-desktop-amd64.iso镜像缺省安装ubuntu,用户名odoo,密码123456 安装open vm tools:使用odoo/123456登录ubuntu桌面,打开Terminal窗口,执行下述命令安装open vm tools:sudo apt-get install open-vm-toolbox 安装ubuntu最新更新: sudo apt-get update &

macOS Sierra(10.12.6), odoo(11.0), Python(3.5.4)配置

欣闻odoo11支持python3环境了,赶紧在mac平台尝试一下: 前期设置,参考另篇文章:macOS Sierra 10.12.6 odoo 10.0 开发环境配置 因为odoo11尚未正式发布,11版本号源码分支还没有建立,我们从master分支获取最新11源码,为了加快速度,仅获取最新源码,以后可以删除odoo11目录,重复本操作更新至最新源码: cd ~/odoo-dev/odoo git clone https://github.com/odoo/odoo.git --depth 1

CentOS 7.x里yum安装Odoo 8.0&9.0(OpenERP)

(总结)CentOS 7.x里yum安装Odoo 8.0&9.0(OpenERP) 最近想了解下合适中小企业使用的ERP系统,研究了几款主流的开源ERP系统以及了解下SAP.Oracle EBS等大型ERP系统,开源ERP里Odoo(以前叫OpenERP)是最有名的,听说在欧洲广泛使用.功能确实非常强大,默认有中文语言包,使用Python开发,数据库用了PostgreSQL,缺点是不支持MySQL.官方有yum源,在CentOS 7.x里使用yum安装部署比较快速,但如果稍不注意细节,可能就会安