Home > OpenERP, Python, XML > OpenERP many2many Domain Filtering Example

OpenERP many2many Domain Filtering Example

Class 1:

class cms_program_specialization_type(osv.osv):
    _name = 'cms.program.specialization.type'
    _columns = {
        'name': fields.char('Specialization Type',size=100,required=True),
    }
cms_program_specialization_type()

Class 2:

class cms_program_specialization(osv.osv):
    _name = 'cms.program.specialization'
    _columns = {
        'name': fields.char('Specialization',size=100,required=True),
        'specialization_type': fields.many2one('cms.program.specialization.type', 'Specialization Type', required=True),
    }
cms_program_specialization()

 

 

Class 3: This is the object where many2many is define:

class cms_course(osv.osv):
    _name = 'cms.course'
    _columns = {
        'name': fields.char('Course Name',size=300,required=True),
        'taught_in_specialization_main': fields.many2one('cms.program.specialization.type','Main Specialization'),
        'taught_in_specialization_detail': fields.many2many('cms.program.specialization', 'tbl_course_in_specialization_rel', 'course_id', 'specialization', 'Course Taught in', required=True),
    }
cms_course()

Now the for view of object cms.course where domain filter is used

    <record model="ir.ui.view" id="view_cms_course_form">
        <field name="name">cms.course.form</field>
        <field name="model">cms.course</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="cms.course">
                <field name="name"/>
		<field name="taught_in_specialization_main"/>
		<field name="taught_in_specialization_detail" colspan="4" domain="[('specialization_type','=',taught_in_specialization_main)]"/>
            </form>
        </field>
    </record>
Categories: OpenERP, Python, XML
  1. vardan
    January 6, 2012 at 10:05 am

    very well explained..

  2. maniganda
    October 30, 2012 at 11:23 am

    its very clear to understand thank you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: