简体   繁体   中英

Add <h1> title to inherited form - Odoo v9 community

I'm inheriting fleet.vehicle.log.services view, so far I've added some lines to the form, like this:

<record model='ir.ui.view' id='fleet_vehicle_log_services_form_inherit'>
        <field name='name'>fleet.vehicle.log.services.form</field>
        <field name='model'>fleet.vehicle.log.services</field>
        <field name='inherit_id' ref='fleet.fleet_vehicle_log_services_form'/>
        <field name="priority">90</field>
        <field name='arch' type='xml'>
            <xpath expr="//form/sheet/group" position="after">
                <group string="Ubicaciones de Productos" col="2">
                    <field name="x_location_src_id" />
                    <field name="x_location_dest_id" />
                </group>
                <group string="Products">
                    <field name="x_move_line" nolabel="1" widget="one2many_list" context="{'x_location_src_id':x_location_src_id, 'x_location_dest_id':x_location_dest_id}">
                        <tree decoration-info="state == 'draft'" decoration-muted="state in ('cancel','done')" decoration-danger="state in ('confirmed','waiting')" string="Products to Consume">
                            <field name="product_id"/>

                            <field name="product_uom_qty"  string="Quantity"/>
                            <field name="product_uom" options="{'no_open':True,'no_create':True}" string="Unit of Measure" groups="product.group_uom"/>
                            <field name="state" invisible="1"/>
                        </tree>
                    </field>
                </group>
            </xpath>
        </field>
    </record>

So far, so good.

Now, I want to add an <h1> element in the top of the form, is is a sequence I've made.

But the problem is, that it says it doesn't find the <h1> element in parent view, of course, it is not present, I'm trying to add it from this inherited one, like this:

<record model='ir.ui.view' id='fleet_vehicle_log_services_form_inherit'>
        <field name='name'>fleet.vehicle.log.services.form</field>
        <field name='model'>fleet.vehicle.log.services</field>
        <field name='inherit_id' ref='fleet.fleet_vehicle_log_services_form'/>
        <field name="priority">90</field>
        <field name='arch' type='xml'>
            <h1>
                <field name="name" readonly="1"/>
            </h1>
            <xpath expr="//form/sheet/group" position="after">
                <group string="Ubicaciones de Productos" col="2">
                    <field name="x_location_src_id" />
                    <field name="x_location_dest_id" />
                </group>
                <group string="Products">
                    <field name="x_move_line" nolabel="1" widget="one2many_list" context="{'x_location_src_id':x_location_src_id, 'x_location_dest_id':x_location_dest_id}">
                        <tree decoration-info="state == 'draft'" decoration-muted="state in ('cancel','done')" decoration-danger="state in ('confirmed','waiting')" string="Products to Consume">
                            <field name="product_id"/>

                            <field name="product_uom_qty"  string="Quantity"/>
                            <field name="product_uom" options="{'no_open':True,'no_create':True}" string="Unit of Measure" groups="product.group_uom"/>
                            <field name="state" invisible="1"/>
                        </tree>
                    </field>
                </group>
            </xpath>
        </field>
    </record>

So, my question is, how can I add this on top of the form, by inheriting it?

The original form code is like this:

 <record model='ir.ui.view' id='fleet_vehicle_log_services_form'>
        <field name="name">fleet.vehicle.log.services.form</field>
        <field name="model">fleet.vehicle.log.services</field>
        <field name="arch" type="xml">
            <form string="Services Logs">
                <sheet>
                    <group col="2">
                        <group string="Services Details">
                            <field name="vehicle_id" on_change="on_change_vehicle(vehicle_id)"/>
                            <field name="cost_subtype_id" string="Service Type" domain="['|',('category','=','service'),('category','=','both')]" required="1"/>
                            <field name="amount"/>
                        </group>
                        <group string="Odometer Details">
                            <label for="odometer"/>
                            <div class="o_row">
                                <field name="odometer"/>
                                <field name="odometer_unit"/>
                            </div>
                        </group>
                    </group>
                    <group col="2">
                        <group string="Additional Details">
                            <field name="date" />
                            <field name="purchaser_id" />
                            <field name="vendor_id" context="{'default_supplier': True}"/>
                            <field name="inv_ref" />
                        </group>
                    </group>
                    <group string="Included Services">
                        <field name="cost_ids" nolabel="1">
                            <tree string="Included Services" editable="bottom">
                                <field name="cost_subtype_id" string="Service" domain="[('category','=','service')]"/>
                                <field name="amount" sum="Price" string="Indicative Cost"/>
                            </tree>
                        </field>
                    </group>
                    <group string="Notes">
                        <field nolabel="1" name="notes" placeholder="Write here any other information related to the service completed."/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

The issue is, that I've never add an object before a form string how can I add this item before it?

I know I just can't go for the <field name="field" position="before"> sentence.

How can I achieve this?

If i get you right, you want to add the typical "Name" to the form, like in other Odoo form views.

Try the following:

<xpath expr="//form//sheet//group[1]" position="before">
    <div class="oe_title">
        <label for="name" class="oe_edit_only" />
        <h1>
            <field name="name" />
        </h1>
    </div>
</xpath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM