Hello guys!
I really have problem with domain for one2many field.
In the res.company form, I select some partners for the field line_of_business_ids. I save this and it works.
In the view view_partner_property_form (see below) the field line_business_ids of the partner should only offer the values available in the field line_of_business_ids of his own and only company_id. Every partner has a company_id field. And any company has a line_of_business_ids field (in my case).
I'm not able to write this domain myself.
Could you help me?
Thanks to help
I actually have this code :
In Python
class Partner(models.Model):
_inherit = "res.partner"
related_business_id = fields.Many2one('res.partner', string='Related business line')
line_business_ids = fields.One2many(comodel_name='res.partner', inverse_name='related_business_id')
class res_company(models.Model):
_inherit = "res.company"
line_of_business_ids = fields.Many2many(comodel_name='res.partner')
In the xml view
<record id="view_partner_property_form" model="ir.ui.view">
<field name="name">base.view.partner.form.inherit.vtm2</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="category_id" position="after">
<field name="line_business_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company','=', False)]}"
options="{'no_create_edit': True}"
domain="[('id', 'in', 'company_id.line_of_business_ids.ids')]" />
</field>
</field>
</record>
See image of the situation
Edit #1
I have tried all this domains. No success...
domain="[('company_id.line_of_business_ids', 'in', id )]"
domain="[('id', 'in', company_id.line_of_business_ids)]
domain="[ ( 'company_id.line_of_business_ids', '=', [ (6, [0], [id]) ] ) ]
domain="[('company_id.line_of_business_ids.id', 'in', company_id.line_of_business_ids )]"
domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.ids )]"
domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.id )]"
domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.partner_id.id )]"
domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids )]"
domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids[0][2] )]"