Odoo - 字段“product_variant_count”不存在
Odoo - Field `product_variant_count` does not exist
我创建了一个名为 Product_Videos 的自定义模型,它将为一个产品保存多个视频,这是我的模型:
从 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:
来自 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>
但是当我升级模块时,我得到:
Field product_variant_count
does not exist
我不知道这个 product_variant_count 字段来自哪里,但我注意到如果我替换
<field name="model">product.videos</field>
使用其他模型,例如 product.template,效果很好。
有什么想法吗?谢谢
当您在 Odoo 中应用 xml 视图继承时,这意味着(通常)新视图将继承同一模型的现有视图。因此,需要为模型 product.template
定义您的视图 product-video-inherited
才能按预期工作。
为了能够定义模型 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
.[=17= 将显示的所有默认树视图。 ]
我创建了一个名为 Product_Videos 的自定义模型,它将为一个产品保存多个视频,这是我的模型: 从 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: 来自 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>
但是当我升级模块时,我得到:
Field
product_variant_count
does not exist
我不知道这个 product_variant_count 字段来自哪里,但我注意到如果我替换
<field name="model">product.videos</field>
使用其他模型,例如 product.template,效果很好。
有什么想法吗?谢谢
当您在 Odoo 中应用 xml 视图继承时,这意味着(通常)新视图将继承同一模型的现有视图。因此,需要为模型 product.template
定义您的视图 product-video-inherited
才能按预期工作。
为了能够定义模型 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
.[=17= 将显示的所有默认树视图。 ]