我公司的一个重要要求是能够同时搜索客户和潜在客户(统一搜索的排序)。
我已经想出了如何通过创建一个类来实现这一点:
from osv import fields, osv
from openerp import tools
from tools.translate import _
import netsvc
class universal(osv.osv):
_name = "universal_search.model"
_description = "Universal Search"
_auto = False
_columns = {
'name': fields.char('Name', size=128, readonly=True),
'phone': fields.char('Phone', size=128, readonly=True),
'city': fields.char('City', size=128,readonly=True),
'state': fields.char('State', size=128,readonly=True),
'country': fields.char('Country', size=128,readonly=True),
'zip': fields.char('Postal Code', size=128,readonly=True),
'email': fields.char('E-Mail', size=128,readonly=True),
'type': fields.char('Type', readonly=True)
}
_order = 'type asc, name asc'
def init(self, cr):
tools.sql.drop_view_if_exists(cr, 'universal_search_model')
cr.execute("""
CREATE OR REPLACE VIEW universal_search_model AS (
select res_partner.id,res_partner.name,phone,city,zip,email,res_country_state.name as state,res_country.name as country,CASE WHEN is_company=TRUE THEN 'Customer' ELSE 'Contact' END as type
from res_partner
left join res_country_state on res_partner.state_id = res_country_state.id
left join res_country on res_partner.country_id = res_country.id
WHERE customer = TRUE
UNION ALL
select crm_lead.id,crm_lead.name,phone,city,zip,email_from,res_country_state.name as state,res_country.name as country,'Lead' as type
from crm_lead
left join res_country_state on crm_lead.state_id = res_country_state.id
left join res_country on crm_lead.country_id = res_country.id
)
""")
universal()
现在我的问题是当客户点击其中一条记录时能够切换选择哪个视图。显然,如果用户点击Lead记录,他们应该转到主要表单并同样为客户。
我已经看过使用优先级和基于上下文的切换的示例,但这些似乎都没有真正解决我想要做的事情。
编辑清晰度:
基本上,我有2种记录被拉。基于它们的类型,我需要提取不同的继承表单视图。如果记录来自客户,我需要继承并显示:base.view_partner_form。如果记录是潜在客户,我需要显示:crm.crm_case_form_view_leads
任何帮助都将不胜感激。
答案 0 :(得分:0)
以下是如何做到这一点
将每个记录链接到其特定类别的潜在客户或客户视图类型 像这样
这里是你的记录变量
和此对象" your_object_returns_the_view"
your_object_returns_the_view((self, cr, uid, ids, context=None):
.................................
................................
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'here the model',
'type': 'ir.actions.act_window',
'target': 'new',
'name': name,
'context': context
}
编写函数(将视图分别返回到记录类型)" universal"
class universal(osv.osv):
.
.
def your_object_returns_the_view_for_leads(self, cr, uid, ids, context=None):
//here you need to write certain conditions to identify each records (lead
//or customer) and to return two view form
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': ' universal',
'type': 'ir.actions.act_window',
'target': 'new',
'name': name,
'context': context
}
现在在树视图中显示您的操作
<tree>
<a name="your_object_returns_the_view_for_leads" type="object"><field name="field_name_from_universal" /></a>
</tree>
每当点击此记录时,它都会以相应的视图形式返回
答案 1 :(得分:0)
noble_man绝对指出了我正确的方向。以下是我的解决方案基于他给我的起点。虽然还有一点点抛光,但它是功能性的&#34;现在
以下是我的观点:
<record id="universal_tree" model="ir.ui.view">
<field name="name">universal_search.tree</field>
<field name="model">universal_search.model</field>
<field name="context">{"record_type":"installation"}</field>
<field name="arch" type="xml">
<tree string="Results" create="false" delete="false">
<button type="object" string="Open" name="open_full_record" icon="gtk-go-forward" context="{'id':id,'type':type}"/>
<field name="type"/>
<field name="name"/>
<field name="phone"/>
<field name="city"/>
<field name="zip"/>
<field name="country"/>
</tree>
</field>
</record>
现在我的功能。
def open_full_record(self, cr, uid, ids, context=None):
obj = self.browse(cr, uid, ids, context)
if context['type'] == 'Customer':
model = 'res.partner'
elif context['type'] == 'Lead':
model = 'crm.lead'
else:
return False
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': model,
'type': 'ir.actions.act_window',
'target': 'self',
'res_id': context['id'],
'context': context,
}