Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Views are not properly copied

By
Andrius Laukavičius
on 1/29/15, 4:44 AM 483 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.

Andrius, have you tried using "xpath"?

Akhil P Sivan
on 1/29/15, 5:19 AM

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.

NOD Baltic, UAB, Andrius Laukavičius
on 1/29/15, 6:21 AM
0
Andrius Laukavičius
On 1/29/15, 6:55 AM

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> 

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/29/15, 4:44 AM
Seen: 483 times
Last updated: 3/16/15, 8:10 AM