【问题标题】:OpenERP modeling / views: related object inlineOpenERP建模/视图:相关对象内联
【发布时间】:2012-06-21 17:38:15
【问题描述】:

我已经安装了 OpenERP 6.1 内置模块 crm。

因此,我现在的 res.lead 处于活动状态,并且在“Sales->Opportunities”中可见。

我想编辑此对象/视图以显示合作伙伴的帐单邮寄地址。

由于我想在商机表单上执行此操作,因此已经有一个 partner_id。

复制另一个模块,我这样定义我的新模块:

class crm_lead(osv.osv):
    _name = _inherit = 'crm.lead'
    _columns = {
    'billing_address_id': fields.many2one('res.partner.address', 'Partner Billing Address', domain="[('partner_id','=',partner_id),('type','in',['invoice', 'default'])]"),
    }

我将 update_xml 更改为:

    <record model="ir.ui.view" id="crm_case_form_view_oppor">
        <field name="name">Opportunity form (inherit)</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
        <field name="arch" type="xml">
            <data>
                <separator string="Details" position="replace" />
                <field name="description" position="replace">
                    <group colspan="2" col="4">
                        <separator colspan="4" string="Billing" />
                        <field widget="one2many_list" mode="form,tree" name="billing_address_id" colspan="4" nolabel="1" />
                    </group>
                    <group colspan="2" col="4">
                        <separator colspan="4" string="Details" />
                        <field name="description" nolabel="1" colspan="4" />
                    </group>
                </field>
            </data>
        </field>
    </record>

问题是相关对象显示了所有相关字段(正如我猜想的那样)。特别是,它显示了 partner_id 和 company 字段,我想隐藏它们,因为它们应该默认/继承于此机会(或链接的合作伙伴)。

如何隐藏这些字段?我不能简单地添加一堆“相关”字段,因为可能有多个帐单地址。

感谢您的帮助!


编辑:为了更清楚,机会应该只有一个选择的帐单地址,从合作伙伴的发票/默认地址中选择。它应该内嵌显示以便于编辑。

【问题讨论】:

    标签: forms view model openerp


    【解决方案1】:

    有几种方法可以specify the view 处理此类相关字段。您可以像这样使用上下文:

    <field 
        name="order_line" 
        colspan="4" 
        nolabel="1"
        context="{'form_view_ref': 'module.view_id', 'tree_view_ref': 'model.view_id'}"/>
    

    您还可以在父视图中将子记录的整个视图指定为 subview,如下所示:

        <!-- <=== order_line is a one2many field -->
        <field name="order_line" colspan="4" nolabel="1">
            <form>
                <field name="qty"/>
                ...
            </form>
            <tree>
                <field name="qty"/>
                ...
            </tree>
        </field>
    

    【讨论】:

    • 我在写完问题后尝试了第二种方法(子视图),因为它看起来正是我想要的。实际上, res_partner 视图使用子视图来实现这种效果。但是,将其复制到我的 update_xml 中不起作用 - 我仍然得到相同的下拉小部件。我很快就会用第一种方法进行测试。你确定 OpenERP 支持继承视图架构中的子视图吗?
    • 我在 field_views_get 中设置了一些断点,并注意到虽然我的子视图的内容在 __view_look_dom_arch 中进行了评估,但它并没有以最终形式返回(就在工具栏计算之前)。有什么想法吗?
    • 更多测试表明定义的子字段(正确吗?)显示为 xfields['billing_address_id']['views']['form'] 和 xfields['billing_address_id']['views'] ['tree'],但网络客户端拒绝显示它们。
    • 进一步测试似乎归咎于 Web 客户端,它似乎不支持 many2one 字段的子视图。仍在调查中。
    • 是的,这似乎是真的。你会认为这是一个错误吗? web js 从不调用 self.set_embedded_view。感谢您提供有关子视图的提示。标记接受,因为你是正确的,但 OpenERP 是错误的。
    【解决方案2】:

    好的,我有点困惑,因为您将 one2many 小部件放在 many2one 字段上。

    如果要控制 one2many 字段的显示方式,请使用我在my other answer 中提到的子视图或上下文方法。

    如果您想控制 many2one 字段的显示方式,您可以使用相关字段从您选择的记录中提取字段,但我对此表示怀疑。只读可能有效,但我认为编辑多个相关字段并能够更改所选记录没有意义。您也许可以将一些功能字段与可让您写回相关记录的存储功能组合在一起,但它似乎真的会让您的用户感到困惑。

    【讨论】:

    • 是的,我明白为什么我最初的问题可能有点令人困惑。我认为最终“最干净”的方法是创建一个新的小部件和表单视图(很像处于表单模式时的现有 one2many 小部件),它将当前可见的外来对象保存到本地 many2one fk 字段中DB,同时还保存了远程相关对象。但是,这似乎并不完全值得现在的努力:) 再次感谢您的帮助。
    • 是的 CB 最干净的方式来添加新的小部件,这将是你可以通过自己的方式做到这一点的最佳方式。 :)
    【解决方案3】:

    在任何 OE 关系字段中,您可以定义内部视图,例如:

      <field name=""  mode="tree,form">
            <!--Internal tree view for your Relation field model-->
            <tree>
            </tree>
    
            <!--Internal Form view for your Relation field model-->
            <form>
            </form>
      </field>
    

    插件1 Click to Example2 Click to See Example下的示例

    希望对你有所帮助。

    【讨论】:

    • 谢谢,Don Kirkby 已经提到了使用子视图,而且这些示例也是在 one2many 字段上,而不是 many2one 字段上,所以它不能解决我的新问题。
    • ok CB 明白了,在 m2o 字段中,您想根据自己的选择显示一些值
    【解决方案4】:

    现在,如果你想在你的 m2o 文件上添加特定的细节,那么我们还有一些可选的方法,你必须在你的关系模型的 def name_get 上,namge 看起来像:

    name_get(cr, user, ids, context=None)
       Returns the preferred display value (text representation) for the records with 
       the given ids. By default this will be the value of the name column, unless the
       model implements a custom behavior. Can sometimes be seen as the inverse function
       of name_search(), but it is not guaranteed to be.
    
       Rtype :  list(tuple)
       Return : list of pairs (id,text_repr) for all records with the given ids.
    

    因此,在此方法中,您可以决定要显示您的关系字段的字符串。 Example

    我猜这会部分解决你的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2016-04-05
      相关资源
      最近更新 更多