OpenERP自定义日记帐凭证视图

时间:2012-12-06 10:17:19

标签: openerp

我正在尝试进行一个简单的自定义,但由于某些奇怪的原因而无效:

init .py:

import account_voucher_hash

OpenERP的的.py

{
"name" : "Hash Voucher",
"version" : "1.1",
"depends" : [
              'base',
              'account_voucher',
            ],
"author" : "me",
"description": """The Module customizes Vouchers""",

'website': 'http://abc.com',
'init_xml': [],
'update_xml': [
    'account_voucher_view_hash.xml',
],
'demo_xml': [],
'installable': True,
'active': False,
}

account_voucher_hash.py

from osv import fields, osv
import netsvc

class account_voucher_hash(osv.osv):
_name = 'account.voucher'
_inherit = 'account.voucher'
_columns={
          'test1': fields.integer('Test 1'),
          'create_uid': fields.many2one('res.users', 'Created By'),
          'creator_name': fields.related("create_uid", "name", type="char", string="Creator Name"),
          'write_uid': fields.many2one('res.users', 'Modified By'),
          'write_name': fields.related("write_uid", "name", type="char", string="Modifier Name"),
          }
account_voucher_hash()  

account_voucher_view_hash.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
 <data>

    <record id="view_voucher_form" model="ir.ui.view">
        <field name="name">account_voucher_hash_form</field>
        <field name="model">account.voucher</field>
        <field name="type">form</field>
        <field name="priority" eval="15"/>
        <field name="arch" type="xml">
            <field name="inherit_id" ref="account_voucher.view_voucher_form" />
            <field name="arch" type="xml">
                <field name="reference" select="2" position="after">
                    <field name="test1"/>
                    <field name="create_uid"/>
                    <field name="creator_name"/>
                    <field name="write_uid"/>
                    <field name="write_name"/>
                </field>
            </field>
        </field>
    </record>


  </data>
</openerp>

日记帐凭证表单不显示新字段。 我哪里错了?

1 个答案:

答案 0 :(得分:1)

您必须从.py:

中删除create_uid和creator_name
_columns = {
    'test1': fields.integer('Test 1'),
    'create_uid': fields.many2one('res.users', 'Created By', readonly=True),
    'creator_name': fields.related("create_uid", "name", type="char", string="Creator Name"),
    'write_uid': fields.many2one('res.users', 'Modified By'),
    'write_name': fields.related("write_uid", "name", type="char", string="Modifier Name"),
}

“create_uid”必须是只读的。

在.xml中尝试此代码:

<record id="view_voucher_form" model="ir.ui.view">
    <field name="name">account_voucher_hash_form</field>
    <field name="model">account.voucher</field>
    <field name="type">form</field>
    <field name="priority" eval="15"/>
    <field name="inherit_id" ref="account_voucher.view_voucher_form"/>
    <field name="arch" type="xml">
            <field name="reference" select="2" position="after">
                <field name="test1"/>
                <field name="create_uid"/>
                <field name="creator_name"/>
                <field name="write_uid"/>
                <field name="write_name"/>
            </field>
        </field>
</record>