【问题标题】:openerp odoo v11.0 invalid model name erroropenerp odoo v11.0 无效型号名称错误
【发布时间】:2018-04-27 14:02:15
【问题描述】:

我正在尝试构建一个名为 kroshu 的 odoo 模块用于库存管理 我已经写了需要的模型和视图 在我尝试安装我的模块 odoo 服务器后显示此消息

  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>

我的模块名为 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")

我的 action_views.xml 文件:

<?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

我的 __ 初始化 __ .py 文件:

from . import category
from . import product

【问题讨论】:

  • 你能知道解释器是否在编译 Product.py 吗?如果正在处理它,您应该会找到一个 Product.pyc 文件。
  • 这可能只是堆栈溢出中的格式设置,但缩进也会出现在您的 Product.py 文件中。我会修改它。
  • 您提到您的文件名为 Product.py,但是在您的 init.py 文件中您导入了 product。您可能希望确保您的 Product.py 文件实际上是 product.py 以确保它被正确导入。

标签: module odoo


【解决方案1】:

根据你上面所说的。问题很可能是在您的__init__.py 文件中,您正在导入product,但该文件名为Product.py。我也不确定Product.py 中的缩进,但这可能只是复制并粘贴到堆栈溢出中的内容的格式。

【讨论】:

    【解决方案2】:

    在编写新模块时,为了调试一般设置,可能有助于先简化,然后逐步添加,保持工作正常。

    在您的情况下,首先创建一个具有一个字段的模型(如name)并使其工作。然后,添加更简单的字段、视图和操作。确保您可以为新模型创建记录。

    然后,添加关系字段,确保在目标模型所在的清单文件中包含依赖项(在您的情况下,product 用于 product. product 等)

    最后,确保您的第二个模型kroshu.stock 也需要存在,遵循相同的方法。

    【讨论】:

      【解决方案3】:

      您的模型定义中有错误:

      barcode = fields.text("barcode")
      

      而不是:

      barcode = fields.Text("barcode")
      

      将文本更改为文本,您的代码就会变得更好。

      第二种解决方案: 尝试重命名您的模型名称,更改

      _name = 'kroshu.product'
      

      例如:

      _name = 'kroshuproduct'
      

      Odoo 通常使用此表达式来指定模型 product 位于模块名称 kroshup 中,例如.

      此错误主要发生在您的模型中有错误时 定义。检测您的错误,评论所有字段并测试每个 单独的字段。

      希望对您有所帮助!太好了!

      【讨论】:

      • product_description 又出现了一次
      • 您可以在视图中使用多次出现的字段模型,但在模型文件中只有一个定义。
      • 是的。我的意思是代码中还有另一个小写的.textproduct_description = fields.text("product description") 这也需要更正。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多