Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenERP 7-如何在树状视图单击上切换模型/窗体视图?_Python_Openerp_Openerp 7_Odoo - Fatal编程技术网

Python OpenERP 7-如何在树状视图单击上切换模型/窗体视图?

Python OpenERP 7-如何在树状视图单击上切换模型/窗体视图?,python,openerp,openerp-7,odoo,Python,Openerp,Openerp 7,Odoo,我公司的一大要求是能够同时搜索客户和潜在客户,这是一种统一的搜索 我已经通过创建一个类找到了实现方法,如下所示: 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

我公司的一大要求是能够同时搜索客户和潜在客户,这是一种统一的搜索

我已经通过创建一个类找到了实现方法,如下所示:

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记录,他们应该转到Lead表单,客户也一样

我见过使用优先级和基于上下文的切换的例子,但这些似乎都没有真正解决我要做的事情

为清晰起见,请编辑:

基本上,我有两种记录被提取。根据它们的类型,我需要提取一个不同的继承表单视图。如果记录来自客户,我需要继承并显示:base.view\u partner\u表单。如果记录是潜在客户,我需要显示:crm.crm\u case\u form\u view\u leads


任何帮助都将不胜感激。

以下是您的方法

通过将每个记录链接到其特定的类别lead或customer 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
       }
或者,用一种简单的方法,你可以通过将一个对象继承到另一个crm_lead和res_partener来合并这两个记录,并将它们放在同一个树状视图中,你可以用它们的记录值编写xml搜索,我没有尝试过,但我认为这是可能的 附加的 编写将视图分别返回到records类型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>

无论何时点击这条记录,它都会以各自的视图形式返回

noble\u man肯定为我指明了正确的方向。以下是我的解决方案,以他给我的作为出发点。虽然还有一点抛光的余地,但它现在可以正常工作了

以下是我的看法:

<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,
      }