how to locate the new added field in Openerp when two of parent view's fields are repetitive?

StackOverflow https://stackoverflow.com/questions/22396906

  •  14-06-2023
  •  | 
  •  

Question

I'm new to Openerp v 7.0,when I was trying to add one field in my inherited view, it didn't work. I found in parent view ,there were two fields has the same name , does this reason cause the problem?

here is the parent view code:

<page string="Contacts" attrs="{'invisible': [('is_company','=',False), ('child_ids', '=', [])]}" autofocus="autofocus">
                        <field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier}">
                            <kanban>
                                <field name="color"/>
                                <field name="name"/>
                                <field name="title"/>
                                <field name="email"/>
                                <field name="parent_id"/>
                                <field name="is_company"/>
                                <field name="function"/>
                                <field name="phone"/>
                                <field name="street"/>
                                <field name="street2"/>
                                <field name="zip"/>
                                <field name="city"/>
                                <field name="country_id"/>
                                <field name="mobile"/>
                                <field name="fax"/>
                                <field name="state_id"/>
                                <field name="has_image"/>
                                <templates>
                                    <t t-name="kanban-box">
                                        <t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
                                        <div t-att-class="color + (record.title.raw_value == 1 ? ' oe_kanban_color_alert' : '')" style="position: relative">
                                            <a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
                                            <div class="oe_module_vignette">
                                            <a type="open">
                                                <t t-if="record.has_image.raw_value === true">
                                                    <img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
                                                </t>
                                                <t t-if="record.image and record.image.raw_value !== false">
                                                    <img t-att-src="'data:image/png;base64,'+record.image.raw_value" class="oe_avatar oe_kanban_avatar_smallbox"/>
                                                </t>
                                                <t t-if="record.has_image.raw_value === false and (!record.image or record.image.raw_value === false)">
                                                    <t t-if="record.is_company.raw_value === true">
                                                        <img t-att-src='_s + "/base/static/src/img/company_image.png"' class="oe_kanban_image oe_kanban_avatar_smallbox"/>
                                                    </t>
                                                    <t t-if="record.is_company.raw_value === false">
                                                        <img t-att-src='_s + "/base/static/src/img/avatar.png"' class="oe_kanban_image oe_kanban_avatar_smallbox"/>
                                                    </t>
                                                </t>
                                            </a>
                                                <div class="oe_module_desc">
                                                    <div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
                                                        <table class="oe_kanban_table">
                                                            <tr>
                                                                <td class="oe_kanban_title1" align="left" valign="middle">
                                                                    <h4><a type="open"><field name="name"/></a></h4>
                                                                    <i><div t-if="record.function.raw_value">
                                                                        <field name="function"/></div></i>
                                                                    <div><a t-if="record.email.raw_value" title="Mail" t-att-href="'mailto:'+record.email.value">
                                                                        <field name="email"/>
                                                                    </a></div>
                                                                    <div t-if="record.phone.raw_value">Phone: <field name="phone"/></div>
                                                                    <div t-if="record.mobile.raw_value">Mobile: <field name="mobile"/></div>
                                                                    <div t-if="record.fax.raw_value">Fax: <field name="fax"/></div>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </t>
                                </templates>
                            </kanban>
                            <form string="Contact" version="7.0">
                                <sheet>
                                    <field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
                                    <div class="oe_title">
                                        <label for="name" class="oe_edit_only"/>
                                        <h1><field name="name" style="width: 70%%"/></h1>
                                        <field name="category_id" widget="many2many_tags" placeholder="Tags..." style="width: 70%%"/>
                                    </div>
                                    <group>
                                        <field name="function" placeholder="e.g. Sales Director"/>
                                        <field name="email"/>
                                        <field name="phone"/>
                                        <field name="mobile"/>
                                    </group>
                                    <div>
                                        <field name="use_parent_address"/><label for="use_parent_address"/>
                                    </div>
                                    <group>
                                        <label for="type"/>
                                        <div name="div_type">
                                            <field class="oe_inline" name="type"/>
                                        </div>
                                        <label for="street" string="Address" attrs="{'invisible': [('use_parent_address','=', True)]}"/>
                                        <div attrs="{'invisible': [('use_parent_address','=', True)]}" name="div_address">
                                            <field name="street" placeholder="Street..."/>
                                            <field name="street2"/>
                                            <div class="address_format">
                                                <field name="city" placeholder="City" style="width: 40%%"/>
                                                <field name="state_id" class="oe_no_button" placeholder="State" style="width: 37%%" options='{"no_open": True}' on_change="onchange_state(state_id)"/>
                                                <field name="zip" placeholder="ZIP" style="width: 20%%"/>
                                            </div>
                                            <field name="country_id" placeholder="Country" class="oe_no_button" options='{"no_open": True}'/>
                                        </div>
                                    </group>
                                    <field name="supplier" invisible="True"/> <-------------- 1st one
                                </sheet>
                            </form>
                        </field>
                    </page>

 <page string="Sales &amp; Purchases">
                        <group>
                            <group>
                                <field name="user_id"/>
                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                            </group>
                            <group>
                                <field name="customer"/> 
                                <field name="supplier"/><-----------------2nd one
                            </group>
                            <group>
                                <field name="ref"/>
                                <field name="lang"/>
                                <field name="date"/>
                            </group>
                            <group>
                                <field name="active"/>
                            </group>
                        </group>
                    </page>
              ……

there are two fields like in above code. what I wanted to do was added a new field name "product_categ_id" after the field. but it didn't work. here are my codes

<openerp>
<data>
    <record model="ir.ui.view" id="rainsoft_partner_form_view">
        <field name="name">rainsoft_partner.rainsoft_partner</field>
        <field name="type">form</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <field name="title" position="after">
                <field name="QQ" placeholder="input your QQ number here."/>
               <!--<field name="product_categ_id"/>-->
            </field>
            <field name="supplier" position="after"> <-------------it doesn't work
                <field name="product_categ_id"/>
            </field>
            <field name="date" position="replace">
                <field name="date" string="合同开始日期"/>
            </field>
            <field name="date" position="after">
                <field name="contract_end_date" string="合同结束日期" />
            </field>
        </field>
    </record>
    <record model="ir.ui.view" id="rainsoft_partner_tree_view">
        <field name="name">rainsoft_partner.rainsoft_partner</field>
        <field name="type">tree</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_tree"/>
        <field name="arch" type="xml">
                <field name="name" position="before" >
                    <field name="ref" string="No"/>
                </field>
        </field>
    </record>
</data>

but when I replace " name='supplier' " by " name='customer' " it works, I guess coz the "customer" only show once in the code.

Anyone here has the resolution? Thanks a lot.

Était-ce utile?

La solution

I've found the solution: using the xpath instead of the way using field name positioning.

here is my new code:

<openerp>
<data>
    <record id="res_partner_view_supplier_product_categ" model="ir.ui.view">
        <field name="name">res.partner.view.supplier.product_categ</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="priority" eval="40"/>
        <field name="arch" type="xml">
            <xpath expr="/form/sheet/notebook/page[@string='Sales &amp; Purchases']/group/group/field[@name='supplier']" position="after">
              <field name="product_categ_id" attrs="{'invisible': [('supplier', '=', False)]}"/>
            </xpath>
        </field>
    </record>
  </data>

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top