【问题标题】:Odoo 10: Open a form view in an editable tree viewOdoo 10:在可编辑的树视图中打开表单视图
【发布时间】:2017-07-26 02:55:38
【问题描述】:

我正在 Odoo 10 中创建一个新模型。 这个模型是通过一个启动树视图的菜单项来访问的。

树视图是可编辑的,但如果用户愿意,我希望能够为用户正在编辑的特定记录启动表单视图。

是否有任何选项可以在树视图中放置一个按钮以启动表单视图或其他什么?有人可以突出显示所需的步骤或指向类似的代码示例吗?

谢谢,

【问题讨论】:

    标签: openerp odoo-10


    【解决方案1】:

    使用按钮: 在树视图中:

     <tree editable="top">
            ...
            ...
          <button name="open_record" type="object" class="oe_highlight"/>
      </tree>
    

    在您的模型中:

      @api.multi
      def open_record(self):
        # first you need to get the id of your record
        # you didn't specify what you want to edit exactly
        rec_id = self.someMany2oneField.id
        # then if you have more than one form view then specify the form id
        form_id = self.env.ref('module_name.form_xml_id')
    
        # then open the form
        return {
                'type': 'ir.actions.act_window',
                'name': 'title',
                'res_model': 'your.model',
                'res_id': rec_id.id,
                'view_type': 'form',
                'view_mode': 'form',
                'view_id': form_id.id,
                'context': {},  
                # if you want to open the form in edit mode direclty            
                'flags': {'initial_mode': 'edit'},
                'target': 'current',
            }
    

    【讨论】:

    • 我想编辑选中的行,所以每一行(记录)都有自己的按钮,可以吗?
    【解决方案2】:

    您不需要特殊功能或按钮或其他任何东西来满足此要求。只需在您的菜单操作view_mode 中添加form 视图:

    <record id="my_menu_action" model="ir.actions.act_window">
        <field name="name">Action</field>
        <field name="res_model">my.model</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="my_tree_view" />
    </record>
    

    在可编辑列表视图中编辑条目时,您可以通过客户端右上角的视图切换器切换到表单视图。

    注意:在更高版本的 Odoo 中不起作用。

    【讨论】:

      【解决方案3】:

      转到树视图,并删除属性editable="bottom"

       <tree editable="bottom" string="Journal Items">
            <field name="account_id" domain="[('company_id', '=', parent.company_id), ('deprecated', '=', False)]"/>
        </tree>
      

      删除该属性后,表单视图将打开

      【讨论】:

        猜你喜欢
        • 2021-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-29
        • 1970-01-01
        相关资源
        最近更新 更多