openerp odoo v11.0 invalid model name error - module

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!

Related

Odoo: How to add custom category name to app module's search panel?

For example i have app with
category = "custom_category"
How can i add this category to my search panel in app module ?
When I created a category, I thought it would come here automatically, but it didn't.
I found the file, where these categories are defined:
15.0/odoo/odoo/addons/base/data/ir_module_category_data.xml
But something is not right here! When I delete a record from here, for example:
<!-- <record model="ir.module.category" id="module_category_human_resources">-->
<!-- <field name="name">Human Resources</field>-->
<!-- <field name="sequence">45</field>-->
<!-- </record>-->
And update the base module, this (Human Resources) field is still in this menu !?
Why it is not deleted? Any advice?
Model 'ir.module.category' doesn't have delete access rights (ref https://github.com/odoo/odoo/blob/a7f7233e0eae8ee101d745a9813cba930fd03dcb/odoo/addons/base/security/ir.model.access.csv#L20). So once a record is created from the xml file, it will not delete if you comment that code line.
You can directly delete it from the database using delete query.
Odoo will only show categories that do not have a parent and that one of the subcategories is linked to a module.
If the category_id field is defined in the search panel, Odoo will use a custom domain:
domain = [('parent_id', '=', False), ('child_ids.module_ids', '!=', False)]
To show the custom category in the search panel:
First, define the module category as follows:
<record model="ir.module.category" id="module_custom_category">
<field name="name">custom_category</field>
<field name="sequence">99</field>
</record>
<record model="ir.module.category" id="module_child_category">
<field name="name">child_category</field>
<field name="parent_id" ref="module_custom_category"/>
</record>
Then set it in a module __manifest__.py file:
'category': 'custom_category/child_category',
Why Odoo did not remove the category after commenting the XML definition?
Odoo will create two categories with the same name (custom_category) with the following XML IDS:
base.module_category_custom_category
stack15.module_custom_category
And use the first one to show it in the search panel.
When you comment record XML definition and upgrade the module, Odoo will remove the category using the module name as a prefix in its XML id (stack15.module_custom_category) and keep the base category (base.module_category_custom_category), so the custom category will be visible even if you uninstall the module.

Generating a sequence using a field value of other class in the same model file

I am trying to create a sequence that would be on the form_serial_no field of a formdownload model at the click of save button. This form_serial_no field will pick the company_short_code field of companyname model in the same models.py file and padded it with seven(7) digit number e.g CHN0000001 where CHN is the value of company_short_code field and 0000001 is the first sequence of the record.
Below are my code snippets:
models.py code
class CompanyName(models.Model):
_name = 'companyname'
_rec_name = 'company_name'
company_name = fields.Char(string="Company Name", required=True)
company_short_code = fields.Char(string="Company short code", required=True)
class FormDownload(models.Model):
_name = 'formdownload'
name = fields.Many2one('companyname', string="Company Name", ondelete='cascade',
required=True)
form_serial_no = fields.Char(string="Form Serial No", readonly=True)
status = fields.Boolean(string="Status", default=False)
#api.model
def create(self, vals):
vals['form_serial_no'] = vals['name']
if vals:
vals['form_serial_no'] = self.env['ir.sequence'].get('formdownload')
return super(FormDownload, self).create(vals)
sequences.xml code
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Sequence for form download serial number -->
<record id="ref_code_form_serial_no" model="ir.sequence.type">
<field name="name">Sequence for form download serial number</field>
<field name="code">formdownload.form_serial_no</field>
</record>
<record id="seq_form_serial_no" model="ir.sequence">
<field name="name">Sequence for form download serial number</field>
<field name="code">formdownload.form_serial_no</field>
<field name="prefix">company_short_code</field>
<field name="padding">7</field>
<field name="company_id" eval="False"/>
</record>
</data>
</openerp>
When i check the formdownload table there is no record created for form_serial_no field. Kindly help me look into this.
#Emipro Technologies answer should actually work for you because you got the sequence code wrong.
I suspect two reasons why it's not working:
You haven't included sequences.xml in your __openerp__.py file so a call to
name=self.env['ir.sequence'].get('formdownload.form_serial_no') will return False
because the sequence doesn't exist. In other words check "Sequences & identifiers => Sequences" if it really exists in the database.
change <data noupdate=" 1"> to with noupdate set to 1, This means that the xml stored in the database will never be updated once it's created, so even if you change the sequence it won't get updated and you would be working with old code
Some other suggestions.
I can see you're trying to create a dynamic field that picks the company short code and attaches it to the sequence, The sequence prefix takes a Fixed Value and can't be dynamic, the only way to have a dynamic sequence AFAIK is to do it in the create method like this:
#api.model
def create(self, vals):
serial_no = self.env['ir.sequence'].get('formdownload.form_serial_no')
code = self.env['companyname']. \
browse(vals['name']).company_short_code
# merge code and serial number
vals['form_serial_no'] = code + serial_no
return super(FormDownload, self).create(vals)
You also don't need to check vals if there's any value. it would always be set in the create method. so the extra check is useless here.
To get Sequence you need to pass code or id.
Get By Code
name=self.env['ir.sequence'].get('formdownload.form_serial_no')
Get By Id
sequence_id=self.env.ref('module_name.ir_sequence_external_id').ids
name=self.env['ir.sequence'].get_id(sequence_id[0])
In your xml file code is formdownload.form_serial_no
<field name="code">formdownload.form_serial_no</field>
You had taken wrong code to get sequence, due to that reason you are not getting correct result.
This may help you.

Altering base Odoo field via XML file

I am trying to edit the default_code field on the product.product model. I am attempting to make it so the field is no longer copied when duplicating a record. This is the XML record in my module:
<record id="product.field_product_product_default_code" model="ir.model.fields">
<field name="copy" eval="False"/>
</record>
When I import the module, I get an import error. If I comment out this record, the rest of my module imports without an issue, so I believe this is causing the problem. Is it not possible to alter a base field in this manner?

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.

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