我创建了一个名为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 import models,api,fields
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 它工作得很好 .
有任何想法吗 ?谢谢
1 回答
在Odoo中应用xml视图继承时,这意味着(通常)新视图将继承同一模型的现有视图 . 因此,需要为模型
product.template
定义视图product-video-inherited
才能按预期工作 .为了能够定义模型
product.videos
的哪些字段在o2m字段x_videos
上可见,您可以定义子视图,如:或者,您可以为模型
product.videos
定义树视图,该视图不会从任何其他视图继承,以定义将为模型product.videos
显示的所有默认树视图 .