Cuu Nguyen
Cuu Nguyen

Reputation: 11

KeyError every times upgrade Odoo module

I am new to Odoo, I developing a simple module that will add some fields to an existed view. First, I install it to Odoo, it works fine. Then I edit some code, likes add new more field to my module. Now when I upgrade my module with some new code, Odoo display error: KeyError "bla bla". But if I install my new module to another machine, it works fine. Did I miss something? How can I fix it. And, sorry for my bad English, I'm Vietnamese.

Update my code: my_model.py file:

from openerp.osv import fields, osv

class ij_project_form(osv.osv):
_name = 'project.project'
_inherit = "project.project"

_columns = {
    'ij_project_form_id': fields.integer('An integer field', size=11),
    'ij_project_form_des': fields.text('A text field')
}

_defaults ={
    'ij_project_form_id': 0
}

ij_project_form()

my_view.xml file:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="ij_project_form">
        <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">
                <newline/>
                <field name="ij_project_form_id" />
            </xpath>

            <xpath expr='//page[@string="Project Stages"]' position="after">
                <group string="Injection tab" name="sample">
                    <field name="ij_project_form_des" />
                </group>
            </xpath>
        </field>
    </record>
  </data>
</openerp>

Upvotes: 0

Views: 14615

Answers (6)

Ryan_Chau
Ryan_Chau

Reputation: 273

Hi I'm also new too odoo I encountered same problem KeyError: 'some old model' The reason is like other answers, due to stale data in the database

I fixed it by removing the records from db with this command

DELETE FROM ir_model WHERE model = 'yourmodule.oldmodelname';

Upvotes: 0

Meet Vaishnani
Meet Vaishnani

Reputation: 253

This happens with every newcomer in odoo , I also suffered with this "KeyError". Well I changed database by creating new one and Installed all needed modules again. It worked for me .

And about your English ,In Communication words doesn't matter , only understanding is require.

Upvotes: 0

sagar sakaria
sagar sakaria

Reputation: 35

Here you are inherit the project.project model and this model is in project module so you are first set dependencies in v7,v8 openerp.py and if you work on v9 or v10 than manifest.py

'depends':['project']

Upvotes: 3

user7561216
user7561216

Reputation:

This is possibly because here you are inheriting the project module. So in your module's manifest file you have to make depend on the project module eg: In your openerp.py file add the following code

'depends': [ 'project', ],

Cheers!

Upvotes: 0

Ehab
Ehab

Reputation: 612

You should update your __openerp__.py file and make sure you place the depends section correctly.

Here, you inherit the project.project module, so you should add this in the __openerp__.py:

'depends': ['project']

Upvotes: 0

shravan cherukuri
shravan cherukuri

Reputation: 490

1) In odoo the '_name' attribute creates a new table in the backend (i.e., in database). So, when you want to add fields to the existing model (like here 'project.project'), no need to use _name. "_inherit" like above is sufficient.

With the above code it will try to create another table, project_project (which is a base table of odoo, which is already created in database). so, remove the _name in your code and run.

We can use _name along with _inherit, but try to give different name to '_name' attribute. So this conflict wont be raised.

Upvotes: 0

Related Questions