KeyError every times upgrade Odoo module - odoo

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>

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']

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.

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']

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!

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.

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';

Related

How to reference a planning type in a plan

I have a custom odoo module, which extends some existing modules like hr. I want to create an onboarding plan with several predefined tasks in it.
This is my plan acitivity type xml which works at it should. If I update the applikation with this file, I get the desired tasks in the planning types overview.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="hr_plan_activity_type_create_work_contract" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Create work contract</field>
<field name="note">Create the work contract for the employee.</field>
</record>
<record id="hr_plan_activity_type_employee_model_in_erp" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Employee model in ERP</field>
<field name="note">Complete the employee model in ERP (AHV, Banking, etc.)</field>
</record>
</odoo>
This is my plan.xml which should create a plan with the activity types. The creation of the plan works, but if I reference the activity types, I'll get an error message.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids"
eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp')])]"/>
<field name="plan_activity_type_ids"
eval="[(4,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
</odoo>
In the manifest.py file I first load the plan.activity.type.xml and then the plan.xml so this shouldn't be a problem.
This is the error message I get when I try to upgrade my customized module mycompany:
File "C:\Program Files (x86)\Odoo 13.0e\server\odoo\addons\base\models\ir_model.py", line 1670, in xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
odoo.tools.convert.ParseError: "External ID not found in the system: hr.plan.activity.type.hr_plan_activity_type_create_work_contract" while parsing file:/c:/users/myuser/appdata/local/openerp%20s.a/odoo/addons/13.0/mycompany/data/hr/plan.xml:2, near
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="hr.plan.activity.type.hr_plan_activity_type_create_work_contract"/>
</record>
Does anyone have any ideas?
String identifier stored in ir.model.data, can be used to refer to a record regardless of its database identifier during data imports or export/import roundtrips.
External identifiers are in the form module.id (e.g. account.invoice_graph). From within a module, the module. prefix can be left out.
Sometimes referred to as xml id or xml_id as XML-based Data Files make extensive use of them.
In your example you used model_name.id which probably does not exist in the database, to reference hr_plan_activity_type_create_work_contract record you just need to replace the model name with the module name.
I can see from the log message that the module name is mycompany, try to replace the model name with mycompany:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="mycompany.hr_plan_activity_type_create_work_contract"/>
</record>
Update:plan_activity_type_ids is an x2many field
Use the special commands format to set the x2many field values:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
Edit: Only the first one shows up in the GUI
To replaces all existing records in the set by the ids list (using '(6, 0, ids)') you can provide a list of ids inside the triplet. You can find an example in res_partner_demo.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp'), ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
To add an existing record of id id to the set (using (4, id)) you need to provide one id for each triplet. You can find an example in base_groups.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(4,ref('mycompany.hr_plan_activity_type_employee_model_in_erp')), (4,ref('mycompany.hr_plan_activity_type_create_work_contract'))]"/>
Your ref ids are wrong. hr.plan.activity.type.hr_plan_activity_type_create_work_contract is wrong. You get only one . in a reference. its [<module_name>.]ext_id_of_object.
If you reference the object from the same module you don't have to use module name.part
If you can see the database tables. then things you are referencing are in table ir_model_data
So if the thing you are referencing is in your own model then you cant use just hr_plan_activity_type_create_work_contract as a reference or your_model_name.hr_plan_activity_type_create_work_contract

Is it normal fields are not updated after installing modules?

I'm developping a module on OpenERP 7.
It is a very simple code : it has only 1 new field (or column) in python file, and an xpath in the xml. I know it works because one time it was succesfully installed
When I try to install/update my module with the module interface, sometimes the field is added/updated to OpenERP, but sometimes no.
I tried to start/stop and restart Openerp before and after installing my module, but I don't know if it has consequences. I don't have errors or useful thing in the logs.
So fields don't add/update but xml update everytime... Does anyone have an idea of what's going on and a solution ?
python code:
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class StockPickingIn(osv.osv):
_name = "stock.picking.in"
_inherit = "stock.picking.in"
_columns = {
'adquat_ack_recep': fields.boolean('Accusé de réception'),
}
xml code:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_picking_in_form_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.form.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='stock_journal_id']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
<record id="view_picking_in_tree_adquat" model="ir.ui.view">
<field name="name">stock.picking.in.tree.adquat</field>
<field name="model">stock.picking.in</field>
<field name="inherit_id" ref="stock.view_picking_in_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='state']" position="after">
<field name="adquat_ack_recep" />
</xpath>
</field>
</record>
</data>
</openerp>
I think it works to update fields with Command line -u !
But my other problem is not solved : I dont have empty checkboxes in form view
And in form view i can't have this checkbox checked :
I click on edit, i check it and save : the checkbox come back to empty !
I saw in the database the value is saved as true or false, but it's not displayed on the interface
You should see the following error
ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
Because adquat_ack_recep is defined in stock.picking and you add it to stock.picking.in form.
You need to inherit from stock.picking.in.
_inherit = "stock.picking.in"
Edit:
Add adquat_ack_recep field to both models stock.picking and stock.picking.in (stock.picking.in read method was overitten to read values from stock.picking model). Take a look at fields not saving problem
Problem may arises due two instances running at same time. make sure you run single instance. you can also update module through command line this may solve your issue
refer this link for module updation through command line.

openerp odoo v11.0 invalid model name error

i am trying to build an odoo module named kroshu for stock managment
i have wrote the needed models and the views
after i try to install my module odoo server shows this message
File "C:\Program Files (x86)\Odoo 11.0\server\odoo\addons\base\ir \ir_actions.py", line 128, in _check_model
raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
odoo.tools.convert.ParseError: "Invalid model name 'kroshu.product' in action definition.
None" while parsing file:/c:/program%20files%20(x86)/odoo%2011.0/server/odoo/addons/kroshu_khalil_kasmi/data/actions.xml:5, near
<record model="ir.actions.act_window" id="action_kroshu_product">
<field name="name">Product</field>
<field name="res_model">kroshu.product</field>
<field name="view_mode">tree,form</field>
</record>
my module is named Product.py :
from odoo import models,fields
class Product(models.Model):
_name = 'kroshu.product'
product_id = fields.Char("product id",required =True)
product_name = fields.Char("product name",required = True)
product_description = fields.text("product description")
product_type = fields.One2many("product.type","product_type_id",string="type")
product_category = fields.One2many("product.category","product_category_id",string="category")
quantity_on_hand = fields.Integer("quantity on hand",required =True)
forcasted_quantity = fields.Integer("forcasted quantity")
location_in_stock = fields.Char("product location in stock")
barcode = fields.text("barcode")
vendor = fields.One2many("product.vendor","vendor_id",string="vendor/manufacturer")
cost = fields.Float("cost")
stock = fields.One2many("kroshu.stock","stock_id",string="in stock")
my action_views.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<menuitem name="Kroshu" id="kroshu_root_menu"/>
<record model="ir.actions.act_window" id="action_kroshu_product">
<field name="name">Product</field>
<field name="res_model">kroshu.product</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window" id="action_kroshu_product_category">
<field name="name">Product Category</field>
<field name="res_model">product.category</field>
<field name="view_mode">tree,form</field>
</record>
........ still more lines
my __ init __ .py file :
from . import category
from . import product
From what you have stated above. The issue is likely that in your __init__.py file you are importing product however the file is called Product.py. I also am not sure of the indentation within Product.py however this may just be formatting of what was copied and pasted into stack overflow.
When writing a new module, for debugging the general setup, it may help to simplify first and then add step by step, keeping things working.
In your case, first create one model with one field (like name) and get that to work. Then, add more simple fields, a view and an action. Make sure you can create records for your new model.
Then, adding relational fields, make sure to include the dependencies in the manifest file where the target models are (in your case, product for product. product etc.)
Finally, make sure your second model kroshu.stock needs to exist, too, following the same methodology.
You have an error inside your model definition:
barcode = fields.text("barcode")
instead of :
barcode = fields.Text("barcode")
change text to Text and your code 'll become nice.
Second Solution:
try to rename your model name, change
_name = 'kroshu.product'
for example like:
_name = 'kroshuproduct'
Odoo commonly uses this expression to specify that the model product is inside de module name kroshup for example.
This error mostly occur when you have and error inside your Model
definition. to detect your Error, comment all fields and test every
fields alone.
Hope this help you! Great!

Odoo 8 Module - adding a new field to the model

I am getting an error adding a new field to an Odoo 8 module. When I comment it out of the view, it works. When it is in, I get the following error:
ParseError: "ValidateError
Field(s) arch failed against a constraint: Invalid view definition
Error details:
Field filedata does not exist
Error context:
View course.form
This is my models.py file:
from openerp import models, fields, api
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string="Title", required=True)
description = fields.Text()
filedata = fields.Binary('File')
And this is an extract from my view file views/openacademy.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="course_form_view">
<field name="name">course.form</field>
<field name="model">openacademy.course</field>
<field name="arch" type="xml">
<form string="Course Form">
<sheet>
<group>
<field name="name"/>
<field name="description"/>
<field name="filedata" />
</group>
</sheet>
</form>
</field>
</record>
....
Any thoughts?
You should try restarting Odoo server as the field probably hasn't been persisted yet due to the binary field misspelling. Try checking the PostgreSQL database directly using PgAdmin or Sql Workbench to check the field is correctly in place.
Regarding your view, everything seems right.
You should update your module through Odoo interface or with the '-u' option of the odoo.py command.
Regards,
Hello dear add like Binary add in camelcase
filedata = fields.Binary('File')
binary field should be capitalized.
First of all define the field properly as said here:
filedata = fields.Binary('File')
And then Uninstall and reinstall your module.
If the problem still occurs,
Create a new database and try again.

How to link Leads (emails) to Marketing emails sent in Odoo v8?

I have Leads and all my leads have emails set. Now I have sent emails to leads with "Mass Mailings" from "Marketing". But now when I click on my lead I do not see any link between the Lead (email) to emails I have sent with "Mass Mailings".
Is there a way to make a link between Lead (email) to email I have sent?
The information about sent emails is available trough the model mail.mail.statistics. In this model you have everything you need. The following fields may be of interest for your task:
model - as emails may be related to any Odoo model, this field tells you to which model was related the email. You are interested in records with crm.lead in this field
res_id - the id of the corresponding model instance. In your case this fields links you to the id of your lead.
mail_mail_id_int - the id of the objects of type email.email - the emails themselves
etc.
You can use this to create a list of emails related to a lead and show them in the crm lead form.
To do that, create a new Odoo module, extend the crm.lead object adding a One2many relation to the mail.mail.statistics model and extend the crm.lead view to show this new field.
For instance, in a file called models/lead.py in this new module, put the following:
from openerp import models, fields
class crm_lead(models.Model):
_inherit = 'crm.lead'
emails = fields.One2many(comodel_name='mail.mail.statistics',
inverse_name='res_id',
domain=[('model', '=', 'crm.lead')])
crm_lead()
Respectively, to extend the view, create a file views/lead_view.xml like this:
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="mail_crm_stats.crm_lead_form">
<field name="name">mail_crm_stats.crm_lead.form</field>
<field name="model">crm.lead</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#string='Extra Info']"
position="after">
<page string="Emails sent">
<group name="emails">
<div>
<field name="emails" nolabel="1"
class="oe_inline"/>
</div>
</group>
</page>
</xpath>
</field>
</record>
</data>
</openerp>
Now you should see additional tab 'EMails sent' in your lead form. Of course, this is just and example and the module may be improved to show better information about the sent emails. As the case is interesting I may commit soon a new version in the github repository I created for the purpose..
You can download the entire module and test it from my github repository like this:
git clone https://github.com/andreiboyanov/odoo-mails_crm_stats mails_crm_stats
In V8 there is a fields between leads and Marketing Campaign See in any Lead > Extra Info (tab) > Marketing, You can manually add your campaign to that, but if you need to automatically sync then you need to create a new module for that, but just for now you can manually put entry.You can view various modules on here.