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

Many2one field does not display correct values

By
Abdullah Sofan
on 9/26/13, 5:32 PM 2,852 views

I'm a newbie.

I'm learning openerp module development.

I tried to create a simple Many2one field but the values are showing in this format: courses.course_types,1 and courses.course_types,2 and so on.

The class is like this:

    from osv import fields,osv


class courses_course(osv.osv):
    _name = 'courses.course'
    _columns = {
        'name': fields.char('Course Name',size=128,required=True),
        'course_type': fields.many2one('courses.course_types', 'type', 'Course Type'),
    }

courses_course()

class courses_course_types(osv.osv):
    _name = 'courses.course_types'
    _rec_name = 'type'
    _columns = {
        'type': fields.char('Course Type',size=30,required=True, help='Please Enter the course type'),
    }
courses_course_types()

and the view is like this:

    <?xml version="1.0"?>
<openerp>
<data>
<menuitem name="Courses" id="courses"/>
<menuitem name="Courses" parent="courses" id="menu_courses"/>
    <record model="ir.ui.view" id="view_courses_course_types_form">
        <field name="name">courses.course_types.form</field>
        <field name="model">courses.course_types</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="courses.course_types">
                <field name="type" />

            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="view_courses_course_types_tree">
        <field name="name">courses.course_types.tree</field>
        <field name="model">courses.course_types</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="courses.course_types">
                <field name="type" />

            </tree>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_courses_course_types">
        <field name="name">Course Types</field>
        <field name="res_model">courses.course_types</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
    <menuitem name="Courses/Course Types" id="menu_courses_course_types" parent="menu_courses" action="action_courses_course_types"/>


    <record model="ir.ui.view" id="view_courses_course_form">
        <field name="name">courses.course.form</field>
        <field name="model">courses.course</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="courses.course">
                <field name="name" select="1"/>
                <field name="course_type"/>

            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="view_courses_course_tree">
        <field name="name">courses.course.tree</field>
        <field name="model">courses.course</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="courses.course">
                <field name="name"/>
                <field name="course_type"/>

            </tree>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_courses_course">
        <field name="name">Courses</field>
        <field name="res_model">courses.course</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
    <menuitem name="Courses/Courses" id="menu_courses_course" parent="menu_courses" action="action_courses_course"/>


</data>
</openerp>

Can you help me?

1
Lady Sharmane Udtuhan
On 9/26/13, 10:52 PM

Instead of this..

class courses_course_types(osv.osv):
_name = 'courses.course_types'
_rec_name = 'type'
_columns = {
    'type': fields.char('Course Type',size=30,required=True, help='Please Enter the course type'),
}
 courses_course_types()

Change It to this

class courses_course_types(osv.osv):
_name = 'courses.course_types'
_rec_name = 'type'
_columns = {
    'name': fields.char('Course Type',size=30,required=True, help='Please Enter the course type'),
}
   courses_course_types()

In many2one it automatically calls the field with a name "NAME" when returning for the value of many2one

Thank you. It works for me

Abdullah Sofan
on 9/27/13, 5:33 AM

Your welcome :D

Lady Sharmane Udtuhan
on 9/30/13, 1:46 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: 9/26/13, 5:32 PM
Seen: 2852 times
Last updated: 3/16/15, 8:10 AM