如何避免在OpenERP 7中以自定义形式显示字段?

时间:2014-10-21 11:29:08

标签: python xml view openerp openerp-7

我正在使用OpenERP7,我在表单中创建了一个字段。这个字段是下一个字段:

'history': fields.function(_get_history, type='many2many',
                           obj="res.partner.link.category",
                           method=True, string='Categories'),

然后,我在表单中显示它。由于该字段很多,它显示为树,我在下面指定。

<group string="Activity Summary">
    <field name="history" nolabel="1" attrs="{'readonly': 1}">
        <tree string="Categories">
            <field name="active_category" attrs="{'readonly': 1}"/>
            <field name="link_category_id" attrs="{'readonly': 1}"/>
            <field name="type" attrs="{'readonly': 1}"/>
            <field name="date" attrs="{'readonly': 1}"/>
            <field name="observations"/>
            <button name="open_history" type="object" string="View history" icon="terp-calendar"/>
        </tree>
    </field>
</group>

一切都很好,但是,如果我点击其中一条记录,它会在弹出窗口中作为表单打开,并显示一些我不想要的字段。例如,&#34; res.partner.link.category&#34;的对象。拥有属性partner_id,我不想显示它。所以我没有把它写在树里面(这很好用),但是我对表格做了同样的事情,而且这个表现了&#34; res.partner.link.category&#34;的每个属性。这里修改后的代码,我按照自己的意愿展示了表单:

<group string="Activity Summary">
    <field name="history" nolabel="1" attrs="{'readonly': 1}">
        <tree string="Categories">
            <field name="active_category" attrs="{'readonly': 1}"/>
            <field name="link_category_id" attrs="{'readonly': 1}"/>
            <field name="type" attrs="{'readonly': 1}"/>
            <field name="date" attrs="{'readonly': 1}"/>
            <field name="observations"/>
            <button name="open_history" type="object" string="View history" icon="terp-calendar"/>
        </tree>
        <form string="Categories" version="7.0">
            <sheet>
                <group col="4">
                    <field name="active_category"/>
                    <field name="link_category_id" options="{'no_open': True}"/>
                    <field name="type"/>
                    <field name="partner_id" attrs="{'invisible': True}"/>
                </group>
                <group col="4">
                    <field name="date"/>
                    <field name="observations"/>
                </group>
            </sheet>
        </form>
    </field>
</group>

我做错了什么?有没有办法解决它?

1 个答案:

答案 0 :(得分:0)

你必须继承历史并将其替换

试试这个,

<record id="form_id" model="ir.ui.view">
            <field name="name">model.form</field>
            <field name="model">model</field>
            <field name="inherit_id" ref="module_to_inherit.view id"/>
            <field name="arch" type="xml">
                <field name="partner_id" position="replace">
                    <field name="history"/>
                </field>
            </field>
</record>