1

我真的被那个困住了。我在 Odoo 11 上。

这是我想要实现的目标:

  1. 我想在客户看板/树视图中添加自定义默认搜索过滤器

  2. 这个过滤器取决于用户的 company_id 它看起来像这样(在 python 中)

{'search_default_incompany_ids': self.env.user.company_id.name}

这是我所做的:

选项1:

起初我想只是替换现有客户“act_window”中的“上下文”:在我看来:

<record id="base.action_partner_form" model="ir.actions.act_window">
        <field name="context">{"search_default_customer":1, 'search_default_incompany_ids': user.company_id.name}</field>
    </record>

=>我尝试了“user.company_id.name”或“company_id.name”或很多东西,但无法访问此xml中的用户或公司ID...

=> 我只能访问“uid”,我认为这不足以回到 xml 中的“company_id”(?)

所以我选择了一个 python 解决方案:

选项 2:

在 menuitem 中,我重新定义了动作,并使用了一个动作服务器,它本身调用了 python 代码:Menuitem

<menuitem id="sale.res_partner_menu"
              parent="sale.sale_order_menu"
              action="action_partner_form_custom_multicompany"
              sequence="3" groups="sales_team.group_sale_salesman"/>

行动服务器:

<record id="action_partner_form_custom_multicompany" model="ir.actions.server">
        <field name="name">Customers</field>
        <field name="condition">True</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_res_partner"/>
        <field name="state">code</field>
        <field name="code">action = model.list_all_customers()</field>
    </record>

和蟒蛇:

@api.model
def list_all_customers(self):
    context = {"search_default_customer": 1}
    if self.env.user.company_id:
        context.update({'search_default_incompany_ids': self.env.user.company_id.name})

    return {
        'type': 'ir.actions.act_window',
        'res_model': 'res.partner',
        'name': "Customers",
        'view_type': 'form',
        'view_mode': 'kanban,tree,form',
        'target': 'current',
        'context': context,
    }

=> 现在这可以很好地使用我想要的默认搜索过滤器显示看板/树视图。到目前为止,这正是我想要的......

但是,现在从看板/树中,如果我打开一条记录,表单就会打开,并且..如果我刷新表单页面:它会回到看板/列表!这是我的问题!

当然,这不是本机 menuitem + act_window 的行为。

我错过了什么?

编辑 :

我注意到在表单中,url 看起来像这样:web#id=20105&view_type=form&model=res.partner&menu_id=98 => 没有像销售订单中那样的“动作”:web#id=28&view_type=form&model=sale。 order&menu_id=237&action=317 这可能是因为使用的操作是在 python 中而不是存储在 DB 中......有没有办法解决这个问题?

谢谢您的帮助 !

广告

4

0 回答 0