openerp学习笔记 domain 增加扩展支持,例如支持 <field name="domain">[('type','=','get_user_ht_type()')]</field>
2013-07-02 15:34
411 查看
示例代码1,ir_action_window.[b]read :[/b]
# -*- 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>
其它示例代码:
View Code
[b]示例代码2,self.[b]search :[/b]
[/b]
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)
# -*- 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>
其它示例代码:
<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>
View Code
[b]示例代码2,self.[b]search :[/b]
[/b]
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)
相关文章推荐
- asp.net 隐藏页面<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=''>的值
- HTML 学习笔记(一)<h1>、<hr />、<p>、<ol><li>、<ul><li>、<dl><dt><dd>、 、<a name="abc">、href="#abc"、mailto
- <form action="get.php" method="post" id="tform"> <input type="text" name="one"> <a href="jav
- javascript学习笔记——如何修改<a href="#">url name</a>
- How to get file name when user select a file via <input type=“file” />?
- jsp js 函数 传参 只接受<%=request.getAttribute("name")%> 形式
- 表单按回车自动提交 1、当form表单中只有一个<input type="text" name='name' />时按回车键将会自动将表单提交。 <form id='form1' action='a
- struts.xml配置文件中result的语法:<result name="" type="">xxxxx</result>
- <s:textfield name="number" value="%{#student.number}" cssClass="InputStyle"/>
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
- ID和Name的问题------写个<input type="hidden">在后台取不到值
- OpenGL学习笔记[2]:#include< >和#include" "的区别
- <param name="root">Field</param>Action的值与前台获取不对
- MATLAB7.0安装后显示The element type "name" must be terminated by the matching end-tag "</name>".
- 使用action属性接收参数<a href="user/user!add?name=a&age=8">添加用户</a>
- struts.xml配置文件中result的语法:<result name="" type="">xxxxx</result>
- so使用原则(要么不支持,要么全部支持) 固定的运行平台 指定目录:System.load("/data/data/<package-name>/mydir/libmath.so");
- <input type="file" name="filePath" />最简单的解决方法
- Spring 注解 hibernate 实体方法 <property name="packagesToScan" value="com.sise.domain"/>
- 转载:老问题再次发生 “从客户端(userName="<hr />")中检测到有潜在危险的 Request.Form 值” 解决方案