تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
6288 أدوات العرض

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:

    
    
    
        



    
    
    
        





الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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')])
الصورة الرمزية
إهمال

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أكتوبر 20
3442
3
مايو 24
6184
0
ديسمبر 21
3282
1
مايو 21
4824
6
أغسطس 20
7553