This question has been flagged
4 Replies
25614 Views

I'm new to OpenERP, and I've been trying to create a custom module. A trivial module with a single model works fine, but as soon as I try to add a second model (with a view), I get an "Invalid model name in the action definition" error on import.

I am using OpenERP 7.0-20130524-231019, installed using apt-get on a Ubuntu server.

If I comment out the view, the model will import fine, but the second model doesn't appear in to Model list, so I'm sure that the error is legit, but why isn't the second module actually being created?

My files are as follows:

__init__.py:

# -*- coding: utf-8 -*-
import dev

__openerp__.py:

# -*- coding: utf-8 -*-

{
    "name" : "Dev module",
    "version" : "0.1",
    "author" : "Dev",
    'complexity': "easy",
    "description" : """
This is a test
==============

This is only a test.
    """,
    "website" : "[a real URL]",
    "depends" : [],
    "category" : "Dev",
    "sequence": 16,
    "init_xml" : [],
    "demo_xml" : [],
    "update_xml" : ["dev_view.xml",],
    'test': [],
    'installable': True,
    'application': True,
    'active': False,
}

Here's the .py:

class dev_person(osv.Model):
    _name = "dev.person"
    _description = "Person"
    _columns = {
        'name': fields.char('Person Name', size=128, required=True),
        'properties': fields.one2many('dev.property', 'property_id', 'Properties'
    }

dev_person()


class dev_property(osv.Model):
    _name = "dev.property"
    _description = "Property"
    _columns = {
        'name': fields.char('Property Name', size=128, required=True),
        'property_id': fields.many2one('dev.person', 'Person Name', select=True),
    }

dev_property()

And dev_view.xml:

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

<record model="ir.actions.act_window" id="action_dev_person_form">
<field name="name">dev_person</field>
<field name="res_model">dev.person</field>
</record>

<record model="ir.actions.act_window" id="action_dev_property_form">
<field name="name">dev_property</field>
<field name="res_model">dev.property</field>
</record>

<menuitem name="Dev" icon="terp-project" id="dev_menu" />
<menuitem name="Dev" parent="dev_menu" id="dev_menu_header" />

<menuitem name="Person" parent="dev_menu_header" id="dev_menu_person" action="action_dev_person_form" />
<menuitem name="Property" parent="dev_menu" id="dev_menu_property" action="action_dev_property_form" />

</data>
</openerp>

Any thoughts?

Avatar
Discard
Best Answer

if you get the error Invalid model name in the action definition, check the followings

  1. check the model name in the model file you have defined.

  2. In __init__.py file whether the model file is imported or not. 

  3. check for the dependency (in most cases when you use <act_window )

Avatar
Discard
Author Best Answer

I believe that I've solved it.

It turns out that I had a bug in my module's .py file that kept it from compiling (that bug is present in the examples I gave... there's a missing end parenthesis).

This prevented any models from working, except for one model, dev.person, and I'm not sure why.

I finally noticed the problem when I got a compile error on trying to update the openerp package using apt-get. Once I saw that, I fixed the bug, and then started using the command line to update my modules rather than the Web UI. I also made sure that the openerp python process was actually dead when I stopped the server. Serveral times, it wasn't, and the process had to be killed.

Now that I am using openerp -d <database> --update <module>, I'm getting the expected behavior.

Avatar
Discard
Best Answer

Hey Shaun,

I just install your custom module, it works fine without error, i think problem is in your __init__.py file.

have you imported your py file in __init__.py ??? for example, suppose you have py file named test.py, have you imported your py file in __init__.py???

in __init__.py,

import test

The second one problem is, i cant see any view of dev.property object,

I suggest you to make seperate form view, tree view, search view of dev.person object and dev.property object.

Avatar
Discard
Author

Thanks for your response, Ghanshyam! I've edited the question to include my __init__.py, and the rest of the files in the module as well. I definitely am including my module's .py in the import statement (and the other model, which is defined in that same module does successfully get imported).