Scraggesh
Scraggesh

Reputation: 131

Error during module installation due to xml records referring to each other

I'm working on odoo module development, left to me by previous programmer. I figured out how most of the code works, but there are some weird parts, that too hard to understand. One example down below: two records (form and action of this form), that referring to each other

<!-- temp validation action-->
<record id="model_action_id" model="ir.actions.act_window">
            <field name="name">Password validation</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">scores.temp</field>
            <field name="view_type">form</field>
            <field name="target">new</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="Scores.my_specific_view"/>
</record>

<!-- temp validation form-->
<record id="my_specific_view" model="ir.ui.view">
    <field name="name">password.form2</field>
    <field name="model">scores.temp</field>
    <field name="act_window_id" ref="Scores.model_action_id"/>
    <field name="arch" type="xml">
        <form string="Password Form Validation">
            <sheet>
                <group>
                    <field name="user_id" />
                    <field name="password" password="True" default_focus="1"/>
                    <button
                        name="validation"
                        type="object"
                        string="Sign"
                        context="{'password':password,'user_id':user_id,}"
                        class="oe_inline oe_stat_button".
                        icon="fa-check-circle-o"
                    />
                    <button 
                        name="cancel"
                        string="Cancel"
                        special="cancel"
                        class="oe_inline oe_stat_button"
                        icon="fa-stop"
                    />
                </group>
            </sheet>
        </form>
    </field>
</record>

When I'm trying to install this module on a new server, it gives error:

ParseError: "External ID not found in the system: Scores.my_specific_view"

It's searching for my_specific_view, but it's obviously not defined yet at this point. Fun part is, it somehow works on the old server, but I don't exactly understand how. It may be caused by first record, that somehow loaded in memory before reference was made, but that's my only theory. I'll try to find a way to contact programmer, who made it, but it may take a while. Any advices of how to avoid this conflict during installation will be highly appreciated.

upd.

in case, described in 1st answer (changed code below):

<!-- temp validation form-->
<record id="my_specific_view" model="ir.ui.view">
    <field name="name">password.form2</field>
    <field name="model">scores.temp</field>
    <field name="act_window_id" ref="Scores.model_action_id"/>
    <field name="arch" type="xml">
        <form string="Password Form Validation">
            <sheet>
                <group>
                    <field name="user_id" />
                    <field name="password" password="True" default_focus="1"/>
                    <button
                        name="validation"
                        type="object"
                        string="Sign"
                        context="{'password':password,'user_id':user_id,}"
                        class="oe_inline oe_stat_button".
                        icon="fa-check-circle-o"
                    />
                    <button 
                        name="cancel"
                        string="Cancel"
                        special="cancel"
                        class="oe_inline oe_stat_button"
                        icon="fa-stop"
                    />
                </group>
            </sheet>
        </form>
    </field>
</record>

<!-- temp validation action--><!--
<record id="model_action_id" model="ir.actions.act_window">
            <field name="name">Password validation</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">scores.temp</field>
            <field name="view_type">form</field>
            <field name="target">new</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="Scores.my_specific_view"/>
</record>-->

It ends with another errors look like below:

ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Model not found: scores.temp

Error context:
View `password.form2`

Same error message even if the action form remains uncommented.

upd2

In addition to what I've described above, model scores.temp wasn't found because I renamed it before in my models.py file. Now it finally works, problem is solved.

Upvotes: 1

Views: 59

Answers (1)

Alessandro Ruffolo
Alessandro Ruffolo

Reputation: 1575

You can try by defining the view for first, excluding the act_window_id field, then you can define the action. In the end you can update the view adding that field.

This is what I mean

<!-- temp validation form-->
<record id="my_specific_view" model="ir.ui.view">
    <field name="name">password.form2</field>
    <field name="model">scores.temp</field>
<!--        <field name="act_window_id" ref="Scores.model_action_id"/>-->
    <field name="arch" type="xml">
        <form string="Password Form Validation">
        <sheet>
            <group>
                <field name="user_id" />
                <field name="password" password="True" default_focus="1"/>
                <button
                    name="validation"
                    type="object"
                    string="Sign"
                    context="{'password':password,'user_id':user_id,}"
                    class="oe_inline oe_stat_button".
                    icon="fa-check-circle-o"
                />
                <button 
                    name="cancel"
                    string="Cancel"
                    special="cancel"
                    class="oe_inline oe_stat_button"
                    icon="fa-stop"
                />
            </group>
        </sheet>
        </form>
    </field>
</record>

<!-- temp validation action-->
<record id="model_action_id" model="ir.actions.act_window">
        <field name="name">Password validation</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">scores.temp</field>
        <field name="view_type">form</field>
        <field name="target">new</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="Scores.my_specific_view"/>
</record>

<record id="my_specific_view" model="ir.ui.view">
    <field name="act_window_id" ref="Scores.model_action_id"/>
</record>

Upvotes: 1

Related Questions