Khalil Kasmi
Khalil Kasmi

Reputation: 15

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

Upvotes: 0

Views: 1940

Answers (3)

Boston Kenne
Boston Kenne

Reputation: 818

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!

Upvotes: 0

miw
miw

Reputation: 764

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.

Upvotes: 0

Phillip Stack
Phillip Stack

Reputation: 3378

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.

Upvotes: 1

Related Questions