Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
7967 Widoki

I'm trying to add a field "street3" to the form that appears after you click "create" button in "contacts & addresses" tab of the vendor form (res.partner model). I can add a field to this tab after the button, but I can't add it to the form this button generates.

Here is my code:

class add_vendor1099(models.Model):
    _inherit = 'res.partner'
    street3 = fields.Char()
<odoo>	<data>	
<record id="add_vendor1099_view_inherit" model="ir.ui.view">
<field name="name">res.partner.form.inherit</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/notebook/page/field[@name='child_ids']/form/sheet/group/field[@name='street2']" position='after'>
      <field name="street3" placeholder="Street 3..."/>
  </xpath>
</field>
</record>
</data></odoo>
ValueError: Can't validate view:
Element '<xpath expr="//form/sheet/notebook/page/field[@name='child_ids']/form/sheet/group/field[@name='street2']">' cannot be located in parent view 

I tried all kinds of paths to that place where I need to add my field, but it's not working. What is the correct xpath? 

Awatar
Odrzuć
Autor Najlepsza odpowiedź

So I kinda solved my issue, but not on 100%. Here is a piece of code of "base.view_partner_form" that you can get by clicking on "Edit FormView" in the developer mode:

<form string="Contact / Address">                                    
    <sheet>
        <field name="type" required="1" widget="radio" options="{'horizontal': true}"/><hr/>
        <group>
            <group attrs="{'invisible': [('type','=', 'contact')]}">
                <label for="street" string="Address"/>
                    <div>
                        <div class="o_address_format" name="div_address">
                            <field name="street" placeholder="Street..." class="o_address_street"/>
                            <field name="street2" placeholder="Street 2..." class="o_address_street"/>
                            <field name="city" placeholder="City" class="o_address_city"/>
                            <field name="state_id" class="o_address_state" placeholder="State" options="{&quot;no_open&quot;: True}" context="{'country_id': country_id, 'zip': zip}"/>
                            <field name="zip" placeholder="ZIP" class="o_address_zip"/>
                            <field name="country_id" placeholder="Country" class="o_address_country" options="{&quot;no_open&quot;: True, &quot;no_create&quot;: True}"/>
                        </div>
                    </div>
            </group>

and here is what i did to add my custom field "street3" after "street2":

<xpath expr="//div[@name='div_address']/field[@name='street2']" position="after">             		
    <field name="street3" placeholder="Street 3..."/>
</xpath>

But here is what I noticed. If you add "street3" field to the main form and the same field to the form that appears after you click the button in "Contacts" tab then you'll see that they're not linked. What i mean is if you type in "street" and "street2" fields in the main form then you'll see the same input in the same fields on the appeared form after you click a button, but it's not like that when you add your own custom fields.

I think the same field needs to be added somewhere else to make it happen. 


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 15
5940
2
maj 21
3069
1
lis 19
5116
2
lis 18
5234
2
paź 24
1643