0
votes

I have created a custom model called Product_Videos that will hold multiple video for one product, Here is my model : from odoo import models, fields, api

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

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

I then inherited the product model to relate to Product_Videos: from odoo import models, api, fields

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

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

Now I inherited the product template view and added a new tab called videos as follow :

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

Now on the new tab, It only shows the Id of the video on the treeview, I want it to show other fields such as embed code, so I inherited the last view :

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

But when I upgrade the module, I'm getting :

Field product_variant_count does not exist

I have no idea where this product_variant_count field comes from, but I noticed that if I replace

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

With another model such as product.template It works just fine.

Any ideas ? Thank you

1

1 Answers

1
votes

When you apply an xml view inheritance in Odoo, that means(normally) that the new view will inherit an existing view of the same model. So your view product-video-inherited need to be defined for the model product.template to work as you expect.

To be able to define what fields of the model product.videos will be visibles on the o2m field x_videos you could define a subview like:

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

Or you could define a tree view for the model product.videos that no inherit from any other view to define what all the default tree views will display for the model product.videos.