openerp学习笔记 domain 增加扩展支持,例如支持 <field name="domain">[('type','=','get_user_ht_type()')]</field>
示例代码1,ir_action_window.read :
# -*- coding: utf-8 -*-
from openerp.osv import fields,osv
class res_users(osv.osv):
_name = 'res.users'
_inherit = 'res.users'
_columns =
{
'ht_type' :
fields.selection([
('makings',u'材料'),
('theme',u'主题'),
('decorate',u'装修')
],u'类型'),
}
#获取用户具有审核权限的合同类型
def _get_ht_type(self, cr, uid,
context=None):
return
self.browse(cr, uid, uid,
context=context).ht_type
res_users()
# 为 domain 增加扩展支持,使用 get_user_ht_type() 获取用户具有审核权限的合同类型
class
ir_action_window(osv.osv):
_inherit =
'ir.actions.act_window'
def read(self, cr, uid, ids, fields=None, context=None,
load='_classic_read'):
if context
is None:
context = {}
obj_user =
self.pool.get('res.users')
select
= ids
if isinstance(ids, (int,
long)):
select = [ids]
res =
super(ir_action_window, self).read(cr, uid, select, fields=fields,
context=context, load=load)
for r
in res:
mystring =
'get_user_ht_type()'
if mystring in (r.get('domain', '[]') or
''):
r['domain'] = r['domain'].replace(mystring, str(obj_user._get_ht_type(cr,
uid)))
if isinstance(ids, (int,
long)):
if
res:
return
res[0]
else:
return False
return res
ir_action_window()
视图中调用:
<field name="domain">[('type','=','get_user_ht_type()')]</field>
其它示例代码:
# -*- coding: utf-8 -*- from openerp.osv import fields, osv
from openerp import tools class hr_department(osv.osv):
def name_get(self, cr, uid, ids, context=None):
if context is None:
context = {}
if not ids:
return []
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
res.append((record['id'], name))
return res def _dept_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = self.name_get(cr, uid, ids, context=context)
return dict(res) _name = "hr.department"
_columns = {
'name': fields.char('Department Name', size=64, required=True),
'complete_name': fields.function(_dept_name_get_fnc, type="char", string='Name'),
'company_id': fields.many2one('res.company', 'Company', select=True, required=False),
'parent_id': fields.many2one('hr.department', 'Parent Department', select=True),
'child_ids': fields.one2many('hr.department', 'parent_id', 'Child Departments'),
'note': fields.text('Note'),
} _defaults = {
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.department', context=c),
} def _get_members(self, cr, uid, context=None):
mids = self.search(cr, uid, [('manager_id', '=', uid)], context=context)
result = {uid: 1}
for m in self.browse(cr, uid, mids, context=context):
for user in m.member_ids:
result[user.id] = 1
return result.keys() def _check_recursion(self, cr, uid, ids, context=None):
if context is None:
context = {}
level = 100
while len(ids):
cr.execute('select distinct parent_id from hr_department where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
level -= 1
return True _constraints = [
(_check_recursion, 'Error! You cannot create recursive departments.', ['parent_id'])
] hr_department() class ir_action_window(osv.osv):
_inherit = 'ir.actions.act_window' def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
if context is None:
context = {}
obj_dept = self.pool.get('hr.department')
select = ids
if isinstance(ids, (int, long)):
select = [ids]
res = super(ir_action_window, self).read(cr, uid, select, fields=fields, context=context, load=load)
for r in res:
mystring = 'department_users_get()'
if mystring in (r.get('domain', '[]') or ''):
r['domain'] = r['domain'].replace(mystring, str(obj_dept._get_members(cr, uid)))
if isinstance(ids, (int, long)):
if res:
return res[0]
else:
return False
return res ir_action_window() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# -*- encoding: utf-8 -*- from osv import osv, fields class partner_category(osv.osv):
_inherit = 'res.partner.category'
_columns = {
'company_id': fields.many2one('res.company', 'Company',select=1, help="The \"Company\" field is used to filter data in the \"Company Partners\" view.")
} def _get_company(self, cr, uid, id, context=None):
if context is None:
context={}
return self.pool.get('res.partner.category').browse(cr, uid, id, context).company_id.id def _default_company(self, cr, uid, context=None):
if context is None:
context={}
return self.pool.get('res.users').browse(cr, uid, uid, context).company_id.id def onchange_parent_id(self, cr, uid, ids, parent_id, context=None):
if context is None:
context={} v={} if parent_id:
parent_company = self._get_company(cr, uid, parent_id, context)
if parent_company:
v['company_id'] = parent_company
return {'value': v} _defaults = {
'company_id': _default_company,
}
partner_category() class ir_action_window(osv.osv):
_inherit = 'ir.actions.act_window' def read(self, cr, uid, ids, fields=None, context=None,
load='_classic_read'):
select = ids
if isinstance(ids, (int, long)):
select = [ids]
res = super(ir_action_window, self).read(cr, uid, select, fields=fields,
context=context, load=load)
for r in res:
mystring = 'get_company_categories()'
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
if mystring in (r.get('domain', '[]') or ''):
r['domain'] = r['domain'].replace(mystring, str(
self.pool.get('res.partner.category').search(cr, uid, [('company_id', '=', user_obj.company_id.id)])))
if isinstance(ids, (int, long)):
if res:
return res[0]
else:
return False
return res ir_action_window()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
视图中调用:
<record id="action_company_partners_form" model="ir.actions.act_window">
<field name="name">Company Partners</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="domain">[('category_id', 'in', get_company_categories())]</field>
</record>
示例代码2,self.search :
This is an example.
Look to USER_PARTNER_IDS and USER_PAYMENT_MODE_IDS.
Part of example.xml:
<record id="action_income_payment_line_tree" model="ir.actions.act_window">
<field name="name">Входящие платежи</field>
<field name="res_model">payment.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="limit">300</field>
<field name="context">{"search_default_today":1}</field>
<field name="domain">[('partner_id','in','USER_PARTNER_IDS')]</field>
<field name="search_view_id" ref="view_payment_line_search"/>
</record>
<record id="action_outgoing_payment_line_tree" model="ir.actions.act_window">
<field name="name">Исходящие платежи</field>
<field name="res_model">payment.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="limit">300</field>
<field name="context">{"search_default_today":1}</field>
<field name="domain">[('payment_mode','in','USER_PAYMENT_MODE_IDS')]</field>
<field name="search_view_id" ref="view_payment_line_search"/>
</record>
Part of example.py:
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, xtra=None):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
new_args = []
for arg in args:
if type(arg) is not tuple:
new_args += arg
continue
if arg[2] == 'USER_PARTNER_IDS':
new_args += [(arg[0], arg[1], [p.id for p in user.partner_ids])]
elif arg[2] == 'USER_PAYMENT_MODE_IDS':
new_args += [(arg[0], arg[1], [m.id for m in user.payment_mode_ids])]
else:
new_args += [arg]
return super(payment_line, self).search(cr, uid, new_args, offset, limit, order, context, count)
openerp学习笔记 domain 增加扩展支持,例如支持 <field name="domain">[('type','=','get_user_ht_type()')]</field>的更多相关文章
- openerp学习笔记 视图继承(tree、form、search)
支持的视图类型:form.tree.search ... 支持的定位方法: <notebook position="inside"> ...
- openerp学习笔记 domain 的应用
1.在Action中定义,domain用于对象默认的搜索条件: 示例: <record id="action_orders" model="ir.actions.a ...
- openerp学习笔记 tree视图增加复选处理按钮
wizard:用于确认或选择 wizard/sale_multi_action.py # -*- encoding: utf-8 -*-from openerp.osv import fields, ...
- openerp学习笔记 跟踪状态,记录日志,发送消息
跟踪状态基础数据: kl_qingjd/kl_qingjd_data.xml <?xml version="1.0"?><openerp> <d ...
- openerp学习笔记 视图样式(表格行颜色、按钮,字段只读、隐藏,按钮状态、类型、图标、权限,group边距,聚合[合计、平均],样式)
表格行颜色: <tree string="请假单列表" colors="red:state == 'refuse';blue:state = ...
- JavaScript:学习笔记(8)——对象扩展运算符
JavaScript:学习笔记(8)——扩展运算符 对象的扩展运算符 扩展运算符是三个点(...).用于取出参数对象的所有可遍历属性,然后拷贝到当前对象之中. 如上图所示,新建了一个对象a,然后通过扩 ...
- openerp学习笔记 统计、分析、报表(过滤条件向导、分组报表、图形分析、比率计算、追加视图排序)
待解决:图形中当改变分组时,图例不正确 存储比率计算时,分组合计不正确 wizard:过滤条件向导,用于输入过滤条件 wizard/sale_chart.py # -*- cod ...
- openerp学习笔记 对象间关系【多对一(一对一)、一对多(主细结构)、多对多关系、自关联关系(树状结构)】
1.多对一(一对一)关系:采购单与供应商之间的关系 'partner_id':fields.many2one('res.partner', 'Supplier', required=True, sta ...
- openerp学习笔记 搜索视图(自己创建的、自己的、本部门的、本部门及下属部门的、今日的、日期从,日期至、多条件模糊搜索、or、and)
自己创建的: domain="[('create_uid','=',uid)]" 自己的: domain="[('employee_id','=','#kl_user_e ...
随机推荐
- 纯CSS 多图片轮播
今天做东西的时候,遇到一个问题关于图片轮播的问题,以前也接触过(百度 人家的demo改改..),再次遇到这个问题的时候,根据以前的印象找到了demo正信心满满的准备改一下嵌进去,发现 jquery.m ...
- Android学习笔记⑤——UI组件的学习TextView相关
TextView是一个强大的视图组件,直接继承了View,同时也派生出了很多子类,TextView其作用说白了就是在布局中显示文本,有点像Swing编程中的JLabel标签,但是他比JLabel强大的 ...
- Oracle基础 (十一)字符串函数
一.字符串函数 LENGTH(char1,char2) SELECT LENGTH('abc def gh') FROM dual; --获取字符串的长度,包含空格 结果: CONCAT(char1, ...
- Linux_内存查询
查询磁盘使用情况: [root@css-management ~]# df -hl 文件系统 容量 已用 可用 已用% 挂载点 Filesystem Size Used Avail Use% Moun ...
- 浅析vb.net与vb6的不同
vb6.0与vb.net 都是微软公司推出的编程工具,而vb.net是在vb6的基础上发展而来的,其语法与VB6.0相似,但VB.net并不是VB6.0 的简单升级,而是增加了更多特性,其中重要的一点 ...
- c#几个小例子引发的思考
楚广明老师的c#教程每一节都会给出几个小例子让大家联系,对于初学者来说这确实是一件很纠结的事情,下面我把这几个小例子简单的写一下.同时看一下我们学到了什么 1.面向过程版的圆周长面积计算 using ...
- VMware系统运维(十四)部署虚拟化桌面 Horzion View Manager 5.2 配置许可
1.通过网页访问https://conntionserver.testad.local/admin,打开如下图所示页面:输入用户名密码 2.进来以后配置View 许可,点击"编辑许可证&qu ...
- first集合及follow集合
前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...
- ARM嵌入式整理
填空 1指令含义 列出文件列表的ls命令 切换目录的cd命令 创建目录的mkdir命令 删除目录的rmdir命令 复制文件的cp命令 删除文件或目录的rm命令 让显示画面暂停的more命令 连接文件的 ...
- Windows装机指南
开发相关: Anaconda整合了很多python的dependency,方便使用