原文转自: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用法的更多相关文章

  1. odoo 开发 context 上下文的用法

    context   这是一个上下文,运用很灵活  得到整个context   self.context_get() self.env['res.users'].context_get() 得到cont ...

  2. webpack中require.context 用法

    1.require.context(directory, useSubdirectories = false, regExp = /^\.\//) Examples: require.context( ...

  3. (48) odoo的button用法

    button 应用的比较多,这里来汇总一下 按钮<button>,支持的属性     icon  可用的icon在 addons/web/static/src/img/icons     ...

  4. 引用reference作用域scope闭包closure上下文context用法

    引用(reference).作用域(scope).闭包(closure)以及上下文(context)是JavaScript重中之重的基础,也是学习好JavaScript的基础.在这里我以浅显的理解给大 ...

  5. odoo t标签用法

    在odoo中,通过QWeb来对模板进行渲染后加载到浏览器中,而模板中有许多的标签来定制各种需求变化,在这里记录学习过程中碰到的标签定义,以方便查询. 模板中的标签统一都是以"t-" ...

  6. golang context用法详解

    背景 在go服务器中,对于每个请求的request都是在单独的goroutine中进行的,处理一个request也可能设计多个goroutine之间的交互, 使用context可以使开发者方便的在这些 ...

  7. odoo 装饰器用法@api

    摘自:blog.csdn.net/cmzhuang/article/details/52932883 @api.one one装饰符自动遍历记录集,把self重新定义成当前记录.注意,返回值是一个li ...

  8. 【转】Appium_API(翻译+用法说明)

    转自:https://testerhome.com/topics/3711 1.contextscontexts(self): Returns the contexts within the curr ...

  9. react之context

    context是什么 Props属性是由上到下单向传递的 context提供了在组件中共享此类值的方法 context使用 设计目的是共享哪些对于组件来说全局的数据 不要因为仅仅为了避免在几个层级下的 ...

随机推荐

  1. iSCSI网络磁盘

    一.fdisk 划分 分区 [root@server0 ~]# lsblk [root@server0 ~]# fdisk /dev/vdb 三个主分区 , 分别2个G大小 两个逻辑分区 , 分别1个 ...

  2. 【逆向&编程实战】Metasploit中的安卓载荷凭什么吊打SpyNote成为安卓端最强远控

    文章作者:MG1937 QQ:3496925334 CNBLOG:ALDYS4 未经许可,禁止转载 前言 说起SpyNote大家自然不陌生,这款恶意远控软件被利用在各种攻击场景中 甚至是最近也捕获到了 ...

  3. 【SQLite】教程01-SQLite简介与安装

    为什么要用 SQLite? 不需要一个单独的服务器进程或操作的系统(无服务器的). SQLite 不需要配置,这意味着不需要安装或管理. 一个完整的 SQLite 数据库是存储在一个单一的跨平台的磁盘 ...

  4. Mysql 面试题(一网打尽,收藏版)

    文章很长,建议收藏起来,慢慢读! 疯狂创客圈为小伙伴奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : <Netty Zookeeper Redis 高并发实战> 面试必备 + 大厂必备 ...

  5. Java后端精选技术:SpringBoot配置读取

    在早前的博客中曾经写过 Spring 程序通过 Bean 映射实现配置信息的读取. 在SpringBoot 框架中读取配置的方式变得非常多样,这导致读者在搜寻资料时反而容易迷糊. 到底,SpringB ...

  6. 8、inotify和resync的优缺点

    只有对外提供访问的服务需要有端口号,本地服务无端口号: 8.1.inotify的优缺点: 1.优点: 监控文件系统事件变化,通过同步工具实现实时的数据同步 2.缺点: 并发如果大于200个文件(10- ...

  7. Exponentiation java大数

    Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...

  8. springBoot-Quartz快速入门

    springBoot-Quartz快速入门 开发环境 JDK1.8.Maven.Idea 技术栈 SpringBoot 2.1.6.quartz 2.3.0等 数据库准备 说明:数据库脚本由Quart ...

  9. Solon 1.5.11 发布,增加国际化插件

    Solon 是一个轻量的Java基础开发框架.强调,克制 + 简洁 + 开放的原则:力求,更小.更快.更自由的体验.支持:RPC.REST API.MVC.Job.Micro service.WebS ...

  10. AcWing 244. 谜一样的牛

    有n头奶牛,已知它们的身高为 1~n 且各不相同,但不知道每头奶牛的具体身高. 现在这n头奶牛站成一列,已知第i头牛前面有a头牛比它低,求每头奶牛的身高. #include<bits/stdc+ ...