【问题标题】:Odoo - Field `product_variant_count` does not existOdoo - 字段“product_variant_count”不存在
【发布时间】:2019-03-12 07:16:58
【问题描述】:

我创建了一个名为 Product_Videos 的自定义模型,它将为一个产品保存多个视频,这是我的模型: from odoo 导入模型、字段、api

class Product_Videos(models.Model):
    _name = "product.videos"

    embed_id = fields.Char(string='Embed Code Id')
    product_id = fields.Many2one("product.template", "Product")

然后我继承了与 Product_Videos 相关的产品模型: from odoo 导入模型、api、字段

class Product(models.Model):
    _inherit = "product.template"

    # Tab Fields
    x_videos = fields.One2many("product.videos", "product_id", "Videos")

现在我继承了产品模板视图并添加了一个名为视频的新标签,如下所示:

<?xml version="1.0" encoding="utf-8" ?>

<odoo>
    <data>
        <record id="product.tabs-inherited" model="ir.ui.view">
            <field name="name">product.template.tabs</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_only_form_view" />
            <field name="arch" type="xml">
                <xpath expr="//page[@name='notes']" position="after">
                    <page string="Videos" name="videos">
                        <field name="x_videos"/>
                    </page>
                </xpath>
            </field>
        </record>  
    </data>
</odoo>

现在在新标签上,它只在树视图上显示视频的 Id,我希望它显示其他字段,例如嵌入代码,所以我继承了最后一个视图:

<?xml version="1.0" encoding="utf-8" ?>

<odoo>
        <record id="product-video-inherited" model="ir.ui.view">
            <field name="name">product.video.embed</field>
            <field name="model">product.videos</field>
            <field name="inherit_id" ref="product.tabs-inherited" />
            <field name="arch" type="xml">
                <xpath expr="//page[@name='videos']" position="inside">
                    <field name="embed_id" />
                </xpath>
            </field>
        </record>  
</odoo>

但是当我升级模块时,我得到了:

字段product_variant_count 不存在

我不知道这个 product_variant_count 字段来自哪里,但我注意到如果我替换

<field name="model">product.videos</field>

使用另一个模型,例如 product.template 效果很好。

有什么想法吗?谢谢

【问题讨论】:

    标签: model field odoo


    【解决方案1】:

    当您在 Odoo 中应用 xml 视图继承时,这意味着(通常)新视图将继承同一模型的现有视图。因此,您的视图product-video-inherited 需要为模型product.template 定义才能按预期工作。

    为了能够定义模型product.videos 的哪些字段将在o2m 字段x_videos 上可见,您可以定义如下子视图:

        <record id="product.tabs-inherited" model="ir.ui.view">
            <field name="name">product.template.tabs</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_only_form_view" />
            <field name="arch" type="xml">
                <xpath expr="//page[@name='notes']" position="after">
                    <page string="Videos" name="videos">
                        <field name="x_videos">
                            <tree>
                                <field name="embed_id"/>
                            </tree>
                        </field>
                    </page>
                </xpath>
            </field>
        </record>
    

    或者,您可以为模型 product.videos 定义一个树视图,该树视图不会从任何其他视图继承,以定义所有默认树视图将为模型 product.videos 显示的内容。

    【讨论】:

    • 这就是我所缺少的,谢谢。关于您的第二个建议,我尝试定义一个视图模型,例如包含这样的表单+树(下一条评论):
    • product.video.embedproduct.videos
      但它对树视图没有影响,知道为什么吗?
    • 因为您不能在同一记录上定义 2 个视图。
    • 知道了,将视图分隔在两个不同的记录中,现在它运行良好,感谢您的时间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多