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

时间:2015-05-21 08:05:30

标签: openerp openerp-7

我正在 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:

所以,我认为我无法访问具有如此多层次的模型的字段,但是有没有办法实现这一目标,如果是这样,如何实现?我试图制作干燥的东西,但总是最终用OpenERP复制代码。

感谢阅读。

1 个答案:

答案 0 :(得分:2)

你需要定义你的最后一节课。

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

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