Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

working of one2many field?

By
Praveen S
on 7/5/13, 7:20 AM 2,521 views

hi, Anybody give the working of one2many field . Pls explain with an example.

1
fdim
On 7/5/13, 8:04 AM

Here an example :

class my_class(osv.osv):

    _name = 'my.class'
    _columns = {
      'name': fields.char('Reference', size=50),
      'test_lines': fields.one2many('test.lines', 'test_id', 'test Lines'),
}
my_calss()

class test(osv.osv):
    _name = 'test.lines'
    _columns = {
      'test_id': fields.many2one('my_class', 'Parent test', ondelete='cascade',select=True),
      'test': fields.char('Test', size=40),
      'comment': fields.text('Commentaire',size=400),
}
test()

xml view :

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>

<!--
tree view
-->

<record id="test_tree_view" model="ir.ui.view">
            <field name="name">test.tree</field>
            <field name="model">my.class</field>
            <field name="type">tree</field>
            <field eval="7" name="priority"/>
            <field name="arch" type="xml">
                <tree string="TEST">
                    <field name="name"/>
                </tree>
            </field>
        </record>


<!--
form view
-->

<record id="test_form_view" model="ir.ui.view">
            <field name="name">test.form</field>
            <field name="model">my.class</field>
            <field name="type">form</field>
            <field eval="7" name="priority"/>
            <field name="arch" type="xml">
                <form string="TEST">

                    <group colspan="2" col="3">
                    <field name="name"/>
                    </group> 

                <notebook colspan="6">
                    <page string="Tests">

    <field colspan="4" name="test_lines" nolabel="1" widget="one2many_list">
                            <tree editable="bottom" colors="red:test in ()">
                                <field name="test"/>
                                <field name="comment"/>
                            </tree>

                                <form string="Tests ">
                                   <field name="test"/>
                                   <field name="comment"/>
                               </form>
</field>
                    </page>

</notebook> 

                </form>
            </field>
        </record>

<record id="test_action" model="ir.actions.act_window">
            <field name="name">test</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">my.class</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="test_tree_view"/>
 </record>

thanks fdim, pls give an example for creating views for this corresponding fields

Praveen S
on 7/5/13, 8:25 AM

answer edited :)

fdim
on 7/5/13, 8:31 AM

hi fdim i am new to openerp pls give the whole xml file

Praveen S
on 7/5/13, 8:38 AM

Hope that help you

fdim
on 7/5/13, 8:52 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/5/13, 7:20 AM
Seen: 2521 times
Last updated: 3/16/15, 8:10 AM