Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
6377 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen
Autor Beste Antwort

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
Verwerfen

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')]

Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Okt. 20
3491
3
Mai 24
6313
0
Dez. 21
3385
1
Mai 21
4912
6
Aug. 20
7670