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

I want to create a many2many field ??

By
Mohammed Tariq
on 7/4/13, 3:10 AM 1,185 views

I want to create a field in which can select qualifications for each individual like MS,B.Tech,B.Sc etc

1

Ghanshyam Prajapati

--Ghanshyam Prajapati--
1377
| 4 4 8
Pune, India
--Ghanshyam Prajapati--
OpenERP Developer
Ghanshyam Prajapati
On 7/4/13, 3:59 AM

Try Following,

See Following example.

__init__.py

import student

__openerp__.py

{
    'name': 'Student  Data Storage',
    'version': '2.0',
    'author': 'Ghanshyam',
    'depends': ['base'],
    'data': [  # data files to load at module install
        'student_view.xml',  
    ], 
    'demo': [],  # demo data (for unit tests)
}

student.py

from openerp.osv import osv, fields
    class student_info(osv.osv):
        _name='student.info'
        _columns = {
            'name': fields.char('Student Name', size=200, required=True),
            'qualification': fields.many2many('education.qualification','student_qualification_rel', 'student_info_id','qualification_id','Education Qualification')
    }
    class education_qualification(osv.osv):
        _name = 'education.qualification'
        _columns = {
            'name' : fields.char('Qualification Name',size=100,required=True),
            'student_id': fields.many2one('student.info','Student'),
    }

student_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <menuitem id="student_main_menu" name="Students"/>

         <record id="student_info_tree_view" model="ir.ui.view">
            <field name="name">student.info.tree</field>
            <field name="model">student.info</field>
            <field name="arch" type="xml">
                <tree string="Student Information">
                    <field name="name"/>
                </tree>
            </field>
        </record>

        <record id="student_info_form_view" model="ir.ui.view">
            <field name="name">student.info.form</field>
            <field name="model">student.info</field>
            <field name="arch" type="xml">
                <form string="Student Information" version="7.0">
                    <group col="4" colspan="4">
                        <field name="name" colspan="4"/>
                        <separator colspan="4" string="Education Qualification"/>
                        <field name="qualification" nolabel="1" colspan="4"/>
                    </group>
               </form>
            </field>
        </record>

        <record id="student_normal_action" model="ir.actions.act_window">
            <field name="name">Student</field>
            <field name="res_model">student.info</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>


        <record id="education_qualification_tree_view" model="ir.ui.view">
            <field name="name">education.qualification.tree</field>
            <field name="model">education.qualification</field>
            <field name="arch" type="xml">
                <tree string="Education Qualification">
                    <field name="name"/>
                </tree>
            </field>
        </record>

        <record id="education_qualification_form_view" model="ir.ui.view">
            <field name="name">education.qualification.form</field>
            <field name="model">education.qualification</field>
            <field name="arch" type="xml">
                <form string="Education Qualification" version="7.0">
                    <group col="4" colspan="4">
                        <field name="name"/>
                    </group>
               </form>
            </field>
        </record>


        <menuitem id="section_main_menu" parent="student_main_menu" name = "View"/>
        <menuitem id="student_real_menu" parent="section_main_menu" action="student_normal_action"/>

    </data>
</openerp>

Hope this work for you.

Hey Tariq, please mark my answer if it worked for you. Thanks.

Ghanshyam Prajapati
on 7/4/13, 10:03 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/4/13, 3:10 AM
Seen: 1185 times
Last updated: 3/16/15, 8:10 AM