OpenERP 7 Adding Field to Existing Module - XML Validate Error

徘徊边缘 提交于 2019-12-11 20:48:32

问题


I'm new to editing/programming OpenERP modules so I'm following this tutorial to simply add a field to the projects module. I've run into a few errors and I've fixed them all, but now my XML simply won't validate. I've read multiple forum posts, read every similar post here on stackoverflow and I can't figure out my problem. So, here's the server's error log output and my files:

openerp-server.log:

2014-05-28 17:56:13,120 29680 ERROR mct openerp.osv.orm: Can't find field 'mct_projects_machine' in the following view parts composing the view of object model 'project.project':
 * project.project.form

Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model
2014-05-28 17:56:13,122 29680 ERROR mct openerp.addons.base.ir.ir_ui_view: Can't render view  for model: project.project
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_ui_view.py", line 126, in _check_render_view
    fvg = self.pool.get(view.model).fields_view_get(cr, uid, view_id=view.id, view_type=view.type, context=context)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 2278, in fields_view_get
    xarch, xfields = self.__view_look_dom_arch(cr, user, result['arch'], view_id, context=ctx)
  File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 1955, in __view_look_dom_arch
    raise except_orm('View error', msg)
except_orm: ('View error', u"Can't find field 'mct_projects_machine' in the following view parts composing the view of object model 'project.project':\n * project.project.form\n\nEither you wrongly customized this view, or some modules bringing those views are not compatible with your current data model")
2014-05-28 17:56:13,128 29680 ERROR mct openerp.tools.convert: Parse error in /usr/lib/pymodules/python2.7/openerp/addons/mct_projects/mct_projects.xml:4: 
<record model="ir.ui.view" id="mct_projects_project">
         <field name="name">project.project.form</field>
         <field name="model">project.project</field>
         <field name="inherit_id" ref="project.edit_project"/>
         <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']" position="after">
               <field name="mct_projects_machine"/>
            </xpath>
         </field>
      </record>

__init__.py:

from openerp.modules import get_module_resource, get_module_path
import mct_projects

mct_projects.py:

from openerp.osv import fields, osv

class mct_projects(osv.osv):

    _inherit = 'project.project'

    _columnns = {
        'mct_projects_machine': fields.integer('Mct projects Machine', size=11),
        }
    _defaults ={
    }

mct_projects()

mct_projects.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
   <data>
      <record model="ir.ui.view" id="mct_projects_project">
         <field name="name">project.project.form</field>
         <field name="model">project.project</field>
         <field name="inherit_id" ref="project.edit_project" />
         <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']" position="after">
               <field name="mct_projects_machine" />
            </xpath>
         </field>
      </record>
   </data>
</openerp>

__openerp__.py

{
    'name': "MCT project integration",
    'version': "1.0",
    'author': "XYZ",
    'category': "Tools",
    'depends': ['project'],
    'data': ['mct_projects.xml'],
    'demo': [],
    'installable': True,
}

As far as my diagnoses goes it's something wrong with the "arch" field. It seems to be saying that mct_projects_machine isn't a field that was ever created, but I declared it in mct_projects.py so I'm at a loss. I followed the tutorial exactly, and a different post here on stackoverflow was fixed by changing the xpath expression, so I tried that. That is the only difference between how my code is now and the tutorial-and I get the same error either way. Any help would be greatly appreciated.


回答1:


That error is a pretty typical "form has a field that hasn't been added to the model" which is odd as at first glance, your model and module look fine.

The only comments I would make is assuming you are OpenERP 6.1 or greater, you don't need to instantiate your model at the end of mct_projects.py so you can loose the mct_projects().

You should also remove the from openerp.modules... line in your init.py file.

My initial suspicion would be that the field hasn't made it's way into the model. Have a look in the ir_model_fields table or look under Settings -> Database. I would also check your addons path to ensure the code is being found - the addons path is logged as soon as OpenERP starts. As a final idea, run with the debugger and set a break point on your columns to see if the code is being parsed.




回答2:


The solution in my case:

  1. Restart the OpenERP server.
  2. Install or upgrade the module.

For some reason, without the restart, OpenERP was not allowing newly created fields to be added to a view, even though the fields in question were defined in the module that was being installed.



来源:https://stackoverflow.com/questions/23919525/openerp-7-adding-field-to-existing-module-xml-validate-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!