Odoo 9:使用模块向HR Contract添加自定义字段

时间:2016-04-10 05:32:55

标签: odoo-9

我是Odoo的新手。我只需要在HR合同中添加一个简单的自定义字段(即津贴)。我已经按照https://www.odoo.com/forum/help-1/question/add-custom-fields-to-sales-order-45074中给出的教程进行了操作,但是它用于销售订单。我试图将这个概念应用于人力资源合同,但没有成功。我在尝试安装时一直收到错误。

请参阅下面的当前代码。

__的OpenERP __。PY

{
    'name': "hr_contract_customfield",

    'summary': """
        Add custom field to HR Contract""",

    'description': """
        Add custom field to HR Contract
    """,

    'author': "Author",
    'website': "http://www.companyname.com",

    'category': 'Uncategorized',
    'version': '0.1',

     'depends': ['base','hr'],

     'data': [
         'views/views.xml',
        'views/templates.xml',
    ],

    'demo': [
        'demo/demo.xml',
    ],
}

models.py

from openerp import models, fields, api
class hr_contract_customfield(models.Model):
    _inherit = 'hr.contract'
    x_allowance_field = fields.Float('Allowance')

templates.xml

<openerp>
    <data>
        <record id="my_view_hr_contract_form_inherit" model="ir.ui.view">
            <field name="name">my.view.hr.contract.form.inherit</field>
            <field name="model">hr.contract</field>
            <field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='wage']" position="after">
                    <field name="x_allowance_field"/>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

有什么建议吗?

尝试安装时出现错误

Error details:
Field `x_allowance_field` does not exist

Error context:
View `my.view.hr.contract.form.inherit`
[view_id: 882, xml_id: n/a, model: hr.contract, parent_id: 584]
None" while parsing /opt/odoo/addons/custom/hr_contract_customfield/views/templates.xml:3, near
<record id="my_view_hr_contract_form_inherit" model="ir.ui.view">
            <field name="name">my.view.hr.contract.form.inherit</field>
            <field name="model">hr.contract</field>
            <field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='wage']" position="after">
                        <field name="x_allowance_field"/>
                </xpath>
            </field>
        </record>

0 个答案:

没有答案