Help

how to customize one2many field

Closed
Avatar
Susi

The question has been closed

by
Susi
on 01/21/2016 23:15:11

i made new object called 'wtc.city' it has one2many fields called 'city_line'. it contain 3 fields (code, name and state_id) . i want to insert that line to 'res.country.state' just for code and name not contain state_id . but i always get 3 fields. My code shown below :

.py

class wtc_country_state (osv.osv):
    _inherit = 'res.country.state'

   _columns = {

 'city_line': fields.one2many('wtc.city', 'state_id', string='City', readonly=True)

}

.xml

         <record model="ir.ui.view" id="country_state_form_view">
            <field name="name">wtc.country.state.form</field>
            <field name="model">res.country.state</field>
            <field name="inherit_id" ref="base.view_country_state_form"/>
            <field name="arch" type="xml">   
                <xpath expr="//form[@string='State']" position="inside">
                    <separator string="City" />
                    <field name="city_line" nolabel="1" colspan="2"/>
                </xpath>
            </field>
            </record>

anyone can help me?

Avatar
Discard
6 Answers
2
Best Answer

@Susi,

you need to define internal tree,form for your one2many field otherwise it will display all the fields defined in that model.

if you are not defining internal tree,form view than create seprate xml reocrd for form and tree view of your one2many field  model.

Hope this will helps you.

Anil.

 

 

 

Avatar
Discard
1
Avatar
sameer alhwety
Best Answer

try this :

                               <field name="city_line" nolabel="1" colspan="4">
                                    <tree string="City" editable="bottom">
                                        <field name="name"/>  
                                        <field name="code"/>
                                    </tree>
                                </field>

Avatar
Discard
1
Avatar
Susi
Best Answer

dear all i have use tree but its not work

         <record model="ir.ui.view" id="country_state_form_view">
            <field name="name">wtc.country.state.form</field>
            <field name="model">res.country.state</field>
            <field name="inherit_id" ref="base.view_country_state_form"/>
            <field name="arch" type="xml">   
                <xpath expr="//form[@string='State']" position="inside">
                    <separator string="City" />
                    <field name="city_line" nolabel="1" colspan="2"/>
                      <tree string="City" editable="bottom">
                                <field name="name"/>  
                                 <field name="code"/>
                      </tree>
                </xpath>
            </field>
            </record>

 

 

1 Comment
Avatar
Discard
Avatar
Alan Luo
-

you need remove last "/" on line and add after

0
Best Answer

add mode to fild definition like this:

<field name="city_line" nolabel="1" colspan="2" mode="tree">

     <tree>

        <field name="code"/>

        <field name="name"/>

    </tree>

</field>

Avatar
Discard
0
Avatar
odookillsme
Best Answer

your tree implementation wrong
                    <field name="city_line" nolabel="1" colspan="2"/>
                      <tree string="City" editable="bottom">
                                <field name="name"/>  
                                 <field name="code"/>
                      </tree>

you have to put the tree inside the <field> tag you shouldn't self close it please look below again

 

try this instead of "<field name="city_line" nolabel="1" colspan="2"/>"

<field name="city_line" nolabel="1" colspan="2">
     <tree>
         <field name="code"/>
         <field name="name"/>
     </tree>
</field>

 

2 Comments
Avatar
Discard
Avatar
Susi
-

i have try your code but its doesnt work...thanks before

Avatar
odookillsme
-

hmm, try with tree tags instead of form

0
Avatar
Zbik
Best Answer

If I understand you well, use:

<field name="city_line" widget="many2many" nolabel="1" colspan="2"/>

2 Comments
Avatar
Discard
Avatar
Susi
-

its doesnt work

Avatar
Zbik
-

You have defined forms and tree views for wtc.city?