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

Hello, Im trying to set a domain for my One2many field but its not working, it still showing values out of the condition I set in my domain. In my view I have two one2many fields, 1 who is supposed to show the account with the internal_type = payable and other with the value = receivable, but, when I select 1 account from 1 of the one2many fields for example one of the value as payable, it also set that account to my other one2many field who is supposed to only show the "receivable" accounts. 

I also tried to set the domain in the xml but still not working. (for some reason the code of the xml here disappear)

My code: 

class PartnerElectronic(models.Model): _inherit = "res.partner"
    payable_partner_accounting_entries = fields.One2many('ak.partner.accounting.entries', 'partner_id', string='Payable', domain="[('
account_type','='payable')]")
receivable_partner_accounting_entries = fields.One2many('ak.partner.accounting.entries', 'partner_id', string='Receivable', domain="[('account_type','=','receivable')]")

class PartnerPayableAccountingEntries(models.Model):
    _description = 'Partner Accounting Entries'
    _name = 'ak.partner.accounting.entries'

    partner_id = fields.Many2one('res.partner', 'Partner')
    account_id = fields.Many2one('account.account', string='Account')
    account_type = fields.Selection(related='account_id.internal_type', store = True)
    _sql_constraints = [('account_unique','UNIQUE(account_id)',"Partner Account must be unique")]

XML:

    
    
    
        



    
    
    
        





Avatar
Discard
Best Answer

Hi,

The two one2many fields are using the same inverse Many2one field (partner_id) in the co-model. Try with different inverse Many2one field for each of the one2many field.

Regards.

Avatar
Discard
Author Best Answer

I already found the correct answer to achieve what I need

payable_partner_accounting_entries = fields.One2many('ak.partner.accounting.entries', 'partner_id', string='Payable', domain=lambda self: [('account_id.internal_type', '=', 'payable')])    

receivable_partner_accounting_entries = fields.One2many('ak.partner.accounting.entries', 'partner_id', string='Receivable', domain=lambda self: [('account_id.internal_type', '=', 'receivable')])
Avatar
Discard

You don't need to put the domains in lambda functions, you can simply pass the domain value as:

domain=[('account_id.internal_type', '=', 'receivable')]

Related Posts Replies Views Activity
1
Oct 20
2350
3
May 24
4128
0
Dec 21
2185
1
May 21
3380
6
Aug 20
6101