首页 > 解决方案 > 为什么我在尝试安装模块时收到错误“找不到模型:product.print.zpl.barcode”?

问题描述

我想安装我的自定义模块product_print_zpl_barcode,但是当我按下按钮安装时,它显示此错误:

ParseError: "Invalid view definition

D\xe9tails de l'erreur :
Mod\xe8le non trouv\xe9 : product.print.zpl.barcode

Contexte de l'erreur :
Vue `product_print_zpl_barcode.form`
[view_id: 847, xml_id: n/a, model: product.print.zpl.barcode, parent_id: n/a]
None" while parsing [...]/openerp/addons/product_print_zpl_barcode/views/product_print_zpl_barcode_view.xml:5, near

product_print_zpl_barcode_view.xml

<record id="product_print_zpl_barcode_form" model="ir.ui.view">
    <field name="name">product_print_zpl_barcode.form</field>
    <field name="model">product.print.zpl.barcode</field>
    <field name="arch" type="xml">
        <form string="Generate and Print Product Barcode">
            <group name="step1" string="Configuration">
                <field name="state" invisible="1"/>
                <field name="currency_id" invisible="1"/>
                <field name="product_id"/>
                <field name="product_name" attrs="{'readonly': [('state', '=', 'step2')]}"/>
                <field name="pricelist_id" attrs="{'readonly': [('state', '=', 'step2')]}"/>
                <field name="price_uom"/>
                <field name="label_size" attrs="{'readonly': [('state', '=', 'step2')]}"/>
                <field name="nomenclature_id" attrs="{'readonly': [('state', '=', 'step2')]}"/>
                <field name="rule_id"/>
                <field name="barcode_type"/>
                <field name="barcode"/>
                <field name="copies" attrs="{'readonly': [('state', '=', 'step2')]}"/>
            </group>
            <group string="Enter Quantity" attrs="{'invisible': [('barcode_type', '=', 'product')]}">
                <div name="qty_uom">
                    <field name="quantity" attrs="{'readonly': [('state', '=', 'step2')]}" class="oe_inline"/>
                    <field name="uom_id" class="oe_inline"/>
                </div>
            </group>
            <group name="step2" states="step2" string="Label">
                <field name="price"/>
                <field name="zpl_file" filename="zpl_filename"/>
                <field name="zpl_filename" invisible="1"/>
                <field name="zpl_printer_id" required="1"/>
            </group>
            <footer>
                <button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
                <button special="cancel" string="Cancel" class="oe_link" states="step1"/>
                <button name="print_zpl" type="object" string="Print" class="btn-primary" states="step2"/>
                <button name="print_zpl" type="object" string="Print and New" class="btn-primary" context="{'print_and_new': True}" attrs="{'invisible': ['|', ('state', '!=', 'step2'), ('barcode_type', '=', 'product')]}"/>
                <button special="cancel" string="Close" class="oe_link" states="step2"/>
            </footer>
        </form>
    </field>
</record>

<record id="product_print_zpl_barcode_action" model="ir.actions.act_window">
    <field name="name">Generate Barcode</field>
    <field name="res_model">product.print.zpl.barcode</field>
    <field name="view_mode">form</field>
    <field name="target">new</field>
</record>

我想创建一个新模型product.print.zpl.barcode,但即使创建了动作,Odoo 也无法识别新模型。这是代码

标签: pythonxmlodooodoo-9odoo-view

解决方案


因此,请确保您以正确的方式添加模型。你必须考虑到

  • 将此包含在/your_module/__init__.py

    import models
    
  • 将此包含在/your_module/models/__init__.py

    import model_name
    
  • 在文件中包含您的模型/your_module/models/model_name.py

    from openerp import models, fields
    
    
    class YourModel(models.Model):
        _name = 'a.model.name'
    
        field1 = fields.Char()
    
  • 要重新加载 python 文件,您需要重新启动服务器

  • 要重新加载 xml 文件,您需要使用参数重新启动服务--update=your_module。您可以通过按模块表单上的更新按钮进行此更新。

注意:如果您从类继承,则models.TransientModel表的数据将不时被删除。常见的用途是在向导上。如果你想要一个持久模型,你需要继承自models.Model


推荐阅读