This question has been flagged

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')]"/>
					</tree>
				</field>
			</page>
		</notebook>
	</field>
</record>
Avatar
Discard
Best Answer

Hi,

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

domain="[('parent_id','=',parent_id)]

I hope it will work as you want.

Avatar
Discard
Author Best Answer

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. 

Avatar
Discard