Odoo Help


Domain Filter Many2many in Form View based on another field

on 4/14/15, 7:43 AM 6,454 views

I have the following parent object, with One2many relationship to child object

class ParentObject(models.Model)
_name = 'module.parentobject'
field1 = fields.Char(string="Field One")
child_ids = fields.One2many('module.childobject', 'parent_id', string="Children")

class ChildObject(models.Model)
_name = 'module.childobject'
parent_id = fields.Many2one('module.parentobject', ondelete='cascade', string="Parent", required="True")
childField1 = fields.Char()
I want to add a List of these items (either parent or specific children) to the crm.lead and hence I have the following:

 #A line can be linked to "a parent" OR "0 to many children"
class Line(models.Model)    
_name = "module.line"
parent_id = fields.Many2one('module.parent', string="Parent")
child_id = fields.Many2many('module.child','module_line_child', 'line_id', 'child_id', string="Children")
lead_id = fields.Many2one('crm.lead')

class Lead(models.Model)
_inherit = "crm.lead"
line_ids = fields.One2many('module.line', 'lead_id', string="Interested In")

On the lead form view I display the lines and I am trying to restrict the child selection options based on the parent. In other words - only children of the selected parent should appear in the dropdown and not all children. A user should also be able to select a parent without a child (he is interested in all children).

The domain below doesn't work, What am i doing wrong? 

<record model="ir.ui.view" id="lead_webquery_form_view">
	<field name="name">lead.webquery</field>
	<field name="model">crm.lead</field>
	<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
	<field name="arch" type="xml">
		<notebook position="inside">
			<page string="Interested In">
				<field name="line_ids" widget="one2many_list" >
					<tree string="Objects" editable="bottom">
						<field name="parent_id"/>
						<field name="child_id" widget="many2many_tags" domain="[('parent_id','=','parent_id')]"/>


you just need to write down your domain as like below.


I hope it will work as you want.

On 5/19/15, 8:49 AM

That worked thanks

The problem: I had enclosed 'parent_id'  in quotes

I hope this serves as a One2many / Many2one tutorial, with inheritance and the many2many tags object. I could have done with a few samples myself. 

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/14/15, 7:43 AM
Seen: 6454 times
Last updated: 5/19/15, 8:49 AM