This question has been flagged
1 Reply
2503 Views

I have a model. For example let say it is this:

<pre>

class my_model(models.Model):

_name = 'my.model'

field1 = fields.Char('name')

</pre>

It has tree and form views. Both work properly.

Now I have created new model, copying old one:

<pre>

class my_model_template(models.Model):

_name = 'my.model.template'

_inherit = 'my.model'

</pre>

Now till this part, everything is fine. It copies everything from old model. But when it comes to views..

So I did this for my 'my.model.template' views (tree and form):

<pre>

        <record id="view_my_model_template_tree" model="ir.ui.view">
            <field name="name">my.model.template.tree</field>
            <field name="model">my.model.template</field>
            <field name="inherit_id" ref="my_model.view_my_model_tree"/>
            <field name="arch" type="xml">
                <tree string="My Model" position="attributes">
                    <attribute name="string">My Model Template</attribute>
                </tree>
            </field>
        </record>

        <record id="view_my_model_template_form" model="ir.ui.view">
            <field name="name">my.model.template.form</field>
            <field name="model">my.model.template</field>
            <field name="inherit_id" ref="my_model.view_my_model_form"/>
            <field name="arch" type="xml">
                <form string="My Model" position="attributes">
                    <attribute name="string">My Model Template</attribute>
                </form>
            </field>
        </record>

</pre>

But it does not copy views properly. For example tree view only shows name field, when in original view it has four fields. In form view, it seems to show all fields, but those fields are in some random position, without any formatting (that was in old view).

 

P.S. I also asked this in github (https://github.com/odoo/odoo/issues/4966). Also there are screenshots where you could see how looks original form and the one that made copy from it.

Avatar
Discard

Andrius, have you tried using "xpath"?

Author

I guess you didn't understand my issue. Rename string in tree or form works fine. I don't need xpath for that. The problem is with the rest of the fields and their styles that should be copied, but its not. This is not standard inheritance. I'm inheriting from another model that copy was made from.

Author Best Answer

Found what was missing. It seems, you need to specify which view to open for which view mode. Because when you copy another model view, it seems it does not find correct view automatically (even if only one is defined for each mode)

    <record model="ir.actions.act_window.view" id="action_my_model_template_tree">
        <field name="sequence" eval="1"/>
        <field name="view_mode">tree</field>
        <field name="view_id" ref="view_my_model_template_tree"/>
        <field name="act_window_id" ref="action_my_model_template"/>
    </record>     

    <record model="ir.actions.act_window.view" id="action_my_model_template_form">
        <field name="sequence" eval="1"/>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_my_model_template_form"/>
        <field name="act_window_id" ref="action_my_model_template"/>
    </record> 

 

Avatar
Discard