1
votes

I have created a new model. That model inherits other models. Which means my model contains fields of inherited models. Now I am creating a form view of my custom model and in that form view displaying an inherited model field. But the problem is that after displaying the field in view it will display their default view and not the new defined view.

Following is the code:

sample.py


class SurveyCreate(models.Model):

    _name = 'survey.create'
    _inherit = ['survey.survey','survey.question','survey.page']

sample_view.Xml

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>

    <record id="survey_create_form" model="ir.ui.view">
    <field name="name">Survey Form</field>
    <field name="model">survey.create</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group><!-- survey.survey  -->
                    <field name="title"/>
                </group>

                 <group>
                    <h2>survey_survey one2many </h2>
                    <field name="page_ids" mode="tree"/>
                    <tree>
                        <field name="title"/>
                        <field name="question_ids"/>
                        <control>
                            <create name="Add Page"/>
                        </control>
                    </tree> 
                </group>

                <group col="4" colspan="2"><!-- survey.question  -->
                    <field name="question"/>
                    <field name="type"/>
                </group>
            </sheet>
        </form>
    </field>
    </record>

    <record id="survey_create_action" model="ir.actions.act_window">
    <field name="name">Survey Action</field>
    <field name="res_model">survey.create</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="help" type="html">
        <p class="oe_view_noncontent_create">
            Create Survey
        </p>
    </field>
    </record>

    <menuitem id="main_menu" name="Survey Create" action="survey_create_action"/>
</data>
</odoo>

I hope provided decription is clear. If not then please let me know. Also I have attached screen short of form view. or any other alternate way?

Wrong form view for inherited fields

1

1 Answers

1
votes

Try the next structure, where the <tree> tag is inside the tag <field>:

<field name="page_ids" mode="tree">
    <tree>
        <field name="title"/>
        <field name="question_ids"/>
        <control>
            <create name="Add Page"/>
        </control>
    </tree>
</field>