从视图访问模型的继承字段

Access inherited field of a model from a view

我正在研究 OpenERP7,试图访问位于所述相关模型的父模型中的相关字段。如果此时有人理解某些东西,那么你比我聪明得多,所以我将举例说明我正在努力实现的目标:

我的模型:

class trench(osv.osv):

    _name = 'trench'
    _inherit = 'common'

    _columns = {

            'trench_lines': fields.one2many('trench.line', 'trench_id', 'Trench Lines'),
            'trench_depth': fields.one2many('trench.depth', 'trench_id', 'Trench Depth'),

        }

trench()

class trench_common(osv.osv):

    _name = 'trench.common'

    def compute_vals(self, cr, uid, ids, field_name, arg, context):
        ...

    def on_change_values(self, cr, uid, ids, context=None):
        ...

    _columns = {
        'trench_id': fields.many2one('trench', 'Trench', ondelete='cascade', required=True),
        'length' : fields.function(compute_vals, type='float', string="Length", method=True, store=True),        
        }

trench_common()

class trench_line(trench_common):

    _name = 'trench.line'
    _inherit = 'trench.common'

trench_line()

class trench_dig_common(trench_common):

    _name = 'trench.dig.common'
    _inherit = 'trench.common'

    _columns = {
        'length' : fields.float('Length', digits=(6,3)),
        'height' : fields.float('Height', digits=(6,3)),
        'total_m3' : fields.float('Total m3', digits=(6,3)),
        'observation' : fields.text('Observation'),
    }

trench_dig_common()


class trench_depth(trench_dig_common):

    _name = 'trench.depth'
    _inherit = 'trench.common'

trench_depth()

我的看法:

    <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="trench_form" model="ir.ui.view">
            <field name="name">trench.form</field>
            <field name="model">trench</field>
            <field name="inherit_id" ref="common_form" />
            <field name="arch" type="xml">
                <group string="Worksite" position="after">

                <separator string="Progress" />

                <field name="trench_lines">                     
                    <tree editable="bottom">
                        <field name="length"/>
                    </tree>
                </field>
                <separator string="Cumulate Length" />
                <field name="total_length"/>

                <separator string="Trench Particularity" />

                <notebook>
                    <page string="Surdepth">
                        <field name="trench_depth">
                            <tree editable="bottom">
                            <field name="height"/>
                            </tree>
                        </field>
                    </page>
                </notebook>
                </group>
            </field>
        </record>

    </data>


</openerp>

我的错误:

except_orm: ('View error', u"Can't find field 'height' in the following view parts composing the view of object model 'qhse.trench':\n * trench.form\n\nEither you wrongly customized this view, or some modules bringing those views are not compatible with your current data model")
2015-05-21 07:56:28,631 13918 ERROR ahak_production openerp.tools.convert: Parse error in trench_view.xml:4:

所以,我想我无法访问具有这么多层的模型的字段,但有没有办法实现这一点,如果可以,怎么做?我正在尝试做一些 DRY,但总是以使用 OpenERP 复制代码而告终。

感谢阅读。

您需要如下定义最后一个 class。

class trench_depth(trench_dig_common):
    _name = 'trench.depth'
    _inherit = 'trench.dig.common'
trench_depth()

然后您可以访问 "trehch.dig.common" 模型中可用的所有字段。