Skip to Content
Menu
This question has been flagged
2 Replies
5440 Views

I'm adding a spouse line to the res_partner object like

class ResPartner(models.Model):
    _inherit = 'res.partner'
    spouse_ids = fields.One2many('res.partner.spouse.line', 'partner_id', string="Spouse(s)")
    mother_id = fields.Many2one('res.partner', string='Mother')

And corresponding co-model is

class ResPartnerSpouseLine(models.Model):
    _name = 'res.partner.spouse.line'
    partner_id = fields.Many2one('res.partner')
    life_partner_id = fields.Many2one('res.partner', string="Life Partner")

Now I want to filter out the spouse_ids for mother_id. For that in the xml file I tried the following

<field name='mother_id' 
domain="[('id', '!=', id), ('is_company', '!=', True), ('id', 'not in', spouse_ids.life_partner_id)]"/>

But I get the error

 Error: AttributeError: object has no attribute 'life_partner_id'

Again I don't want the mother_id to be shown in the spouse_ids. So  I tried to add a domain for spouse_ids as

<field name='spouse_ids'>
    <tree editable="bottom" default_order="spouse_order"  >
         <field name="partner_id" invisible="1"/>
         <field name="life_partner_id"  domain="[('id', 'not in', partner_id.mother_id)]"/>
    </tree>
</field>

But I get the error 

Error: AttributeError: object has no attribute 'mother_id'

How to properly give domain and filter out those ids. Thanks in advance

Avatar
Discard

Hello,

I think your value is not store in DB so set store= True after check.

Best Answer

Odoo has a inbuilt option called "parent" for one2many relations. So you could use the domain like

<field name="life_partner_id"  domain="[('id', 'not in', parent.mother_id)]"/>
Avatar
Discard
Related Posts Replies Views Activity
0
Mar 24
274
0
Oct 22
1489
0
Sep 22
660
1
Jul 22
4084
0
Jun 22
836