问题
follow the documentation Odoo 9.0, I created a new module which I created a new model as follows:
models.py
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class payModel(models.Model):
_name = 'payModel.payModel'
_inherit = 'hr.employee'
num_CN = fields.Char("CN°")
and my form view:
<record model="ir.ui.view" id="payModel_form_view">
<field name="name">payModel.num_CN</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='bank_account_id']" position="after">
<field name="num_CN"/>
</xpath>
</data>
</field>
</record>
I verirfy in Settings -> Technical -> Database Structure -> Models that the model and the field were added by success But I get this error :
the num_CN does not exist
I try to add this field in employee form view by developer mode but I get the same error!
Can sameone help me what's missing?
回答1:
First of all - about your model.
_name = 'payModel.payModel'
means that when you install module Odoo will create new table with name payModel_payModel. After this in the system will be your custom object - payModel.payModel.
_inherit = 'hr.employee'
means that you expand table hr_employee(Odoo object - hr.employee).
If you want to create new table and use your new object you need to remove _inherit = 'hr.employee'
. If you need to extend the hr.employee(for example add new fields or add some logic to model etc.) you need to remove _name = 'payModel.payModel'
Second problem which can be it is dependencies. If your module depends from hr module you need to mark this in __openerp__.py of your module:
'depends': ['hr'],
And one more thing. Make sure that models.py is imported in __init__.py of your module. Restart openerp-server before updating your module after changes in .py files. Odoo does not see changes in .py files without restart.
Hope this helps you.
来源:https://stackoverflow.com/questions/34490479/odoo-9-field-does-not-exist