我有一个从外部数据库读取的TransientModel,因此我创建了带有功能字段的模型,并且还声明了搜索功能。
这是部分列声明:
_columns = {
'web_id': fields.function(_get_data, string='ID', fnct_search=_search_data, type='integer', method=True, multi='external'),
.....
}
树视图的操作是
<record id="action_preview_orders" model="ir.actions.act_window">
<field name="name">Preview Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">external.data</field>
<field name="view_type">tree</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="preview_orders_view"/>
<field name="target">current</field>
<field name="search_view_id" ref="preview_orders_view_filters"/>
</record>
,搜索视图
<record id="preview_orders_view_filters" model="ir.ui.view">
<field name="name">Preview Filters</field>
<field name="model">external.data</field>
<field name="arch" type="xml">
<search string="Search Orders">
<filter string="Type" icon="terp-accessories-archiver" domain="[('type_order','=','RO')]"/>
</search>
</field>
</record>
数据显示正确,我的问题是没有显示搜索表单。 它出现在html中,但div有style = display:hidden
我可能做错了什么?
我按要求添加了get数据函数,它非常动态。 我不知道这可能是个问题......
def _get_data(self, cr, uid, ids, field_names, arg, context=None):
res = dict.fromkeys(ids)
for k in ids:
res[k] = dict.fromkeys(self._mapper.keys())
for mk in self._mapper.keys():
fmt = self._mapper[mk].get('format', None)
fnc = self._mapper[mk].get('function', None)
params = self._mapper[mk].get('parameters', None)
if params != None:
indexes = [INDEXES[param] for param in params]
values = [self._rows[k][index] for index in indexes]
if fmt != None:
res[k][mk] = fmt.format(*values)
elif fnc != None:
res[k][mk] = fnc(self, cr, uid, *values)
else:
res[k][mk] = ""
else:
res[k][mk] = ""
return res
搜索功能是虚拟的:
def _search_data(self, cr, uid, obj, name, args, context):
return [('id','in',[0])]
答案 0 :(得分:1)
您需要创建函数_search_data (对于fnct_search = _search_data)
def _get_full_name(self, cr, uid, ids, field, arg, context=None):
res = {}
for g in self.browse(cr, uid, ids, context):
if g.category_id:
res[g.id] = '%s / %s' % (g.category_id.name, g.name)
else:
res[g.id] = g.name
return res
def _search_group(self, cr, uid, obj, name, args, context=None):
operand = args[0][2]
operator = args[0][1]
lst = True
if isinstance(operand, bool):
domains = [[('name', operator, operand)], [('category_id.name', operator, operand)]]
if operator in expression.NEGATIVE_TERM_OPERATORS == (not operand):
return expression.AND(domains)
else:
return expression.OR(domains)
if isinstance(operand, basestring):
lst = False
operand = [operand]
where = []
for group in operand:
values = filter(bool, group.split('/'))
group_name = values.pop().strip()
category_name = values and '/'.join(values).strip() or group_name
group_domain = [('name', operator, lst and [group_name] or group_name)]
category_domain = [('category_id.name', operator, lst and [category_name] or category_name)]
if operator in expression.NEGATIVE_TERM_OPERATORS and not values:
category_domain = expression.OR([category_domain, [('category_id', '=', False)]])
if (operator in expression.NEGATIVE_TERM_OPERATORS) == (not values):
sub_where = expression.AND([group_domain, category_domain])
else:
sub_where = expression.OR([group_domain, category_domain])
if operator in expression.NEGATIVE_TERM_OPERATORS:
where = expression.AND([where, sub_where])
else:
where = expression.OR([where, sub_where])
return where
_columns = {
'full_name': fields.function(_get_full_name, type='char', string='Group Name', fnct_search=_search_group),
}
查看res.groups表中的全名
答案 1 :(得分:0)
def _get_full_name(self, cr, uid, ids, field, arg, context=None):
res = {}
for g in self.browse(cr, uid, ids, context):
if g.partner_id.new_ic_number:
res[g.id] = g.partner_id.new_ic_number
elif g.partner_id.old_ic_number:
res[g.id] = g.partner_id.old_ic_number
#~ res[g.id] = '%s / %s' % (g.category_id.name, g.name)
else:
res[g.id] = ''
return res
def _search_customer_ic(self, cr, uid, obj, name, args, context=None):
ids = set()
partner_obj = self.pool.get('res.partner')
partner_ids1 = partner_obj.search(cr,uid,[('new_ic_number','ilike',args[0][2])])
partner_ids2 = partner_obj.search(cr,uid,[('old_ic_number','ilike',args[0][2])])
partner_ids = partner_ids1+partner_ids2
partner_ids = list(set(partner_ids))
agreement_ids = self.search(cr,uid,[('partner_id','in',partner_ids)])
return [('id','in',agreement_ids)]
_columns = {
'ic_number':fields.function(_get_full_name, type='char', string='Customer IC', fnct_search=_search_customer_ic),
}
这是示例代码,用于在协议表(自定义表)中检索基于customer_ic数字的搜索,其中我们有partner_id且没有ic编号,因此我从 res.partner 检索数据( old_ic_number或new_ic_number 和搜索方法在协议表中搜索相同的功能字段