简体   繁体   中英

Show fields from new res.partner contact type on inherited module - Odoo v9 community

I've inherited the res.partner model like this:

class Partner(models.Model):
    _inherit = 'res.partner'

    type = fields.Selection(selection_add=[(('mina', 'Mina'))])
    origen = fields.Char(string="Origen")
    destino = fields.Char(string="Destino")

I have added a new type called "mina"

This new type of contact, should show these two fields only, origen and destino

Tje new radio button is shown on the form, that's Okay, but I can't figure out how to show only those two fields, it just shows the other type of contact fields, this is my view:

        <record id="view_partner_form_1" model="ir.ui.view">
        <field name="name">res.partner.form</field>
        <field name="model">res.partner</field>
        <field name='inherit_id' ref='base.view_partner_form'/>
        <field name="arch" type="xml">
            <xpath expr="//form//sheet//group//notebook" position="after">
                <form string="Minas">
                                <sheet>
                                    <field name="type" required="1" widget="radio" options="{'horizontal': true}"/>
                                    <hr/>
                                    <group>
                                        <group attrs="{'invisible': [('type','=', 'mina')]}">
                                        </group>
                                        <group>
                                            <field name="origen" string="Origen" attrs="{'required' : [('type', '=', 'mina')]}"/>
                                            <field name="destino" string="Destino" attrs="{'required' : [('type', '=', 'mina')]}"/>
                                        </group>
                                    </group>
                                </sheet>
                            </form>
                      </xpath>
               </field>
        </record>

Any ideas on this?

Thanks in advance

Position after means that you append more elements to the view, if you want to modify the existing fields, use position attributes instead. You could make the other fields invisible using below code:

<xpath expr="//field[@name='field_name']" position="attributes">
    <attribute name="attrs">{'invisible': [...]}</attribute>
</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