Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată

i have been trying to get the records from res.partner model and filled the fiels att depeding upon the record 

here is what i want the outcome.
when the partner_id has the attribute is_company is true from res.partner
want to fill the all user under that country in att field  if its individual then only that company record to be filled in that field so im confused that im using the domain correctly whatso ever but i'm not getting the outcome as expected.
this is code snipet 

partner_id = fields.Many2one('res.partner', string='Partner')
att = fields.Many2one('res.partner', string='Attendee') 

    @api.onchange('partner_id')
    def _onchange_partner_id1(self):
        for rec in self:
            if rec.partner_id:
                if rec.partner_id.is_company:
                    return {
                        'domain': {'att': [('id', 'in', rec.partner_id.child_ids.ids)]}
                    }
                else:
                    return {
                        'domain': {'att': [('id', '=', rec.partner_id.id)]}
                    }
            else:
                return {
                    'domain': {'att': []}
                }


appreciate for helping.

Imagine profil
Abandonează
Cel mai bun răspuns

Hello _ALI  ,


Your code snippet is almost correct, but there are a few adjustments needed to achieve the desired functionality. Specifically, you need to handle setting the domain for the att field based on whether the partner_id is a company or an individual correctly. Here’s how you can adjust your code:


    1. Use Many2many for att field if there can be multiple attendees:

       If you intend to allow multiple attendees (which seems likely given your description),

       you should use Many2many instead of Many2one for the att field.


    2. Handle the domain logic correctly:

       Ensure that the domain logic properly filters records based on the is_company attribute.


       Here’s the revised code:


  //Code in Comment//

Hope this Helps,


If you need any help in customization feel free to contact us.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Imagine profil
Abandonează

Code :

from odoo import models, fields, api

class YourModel(models.Model):
_name = 'your.model'
_description = 'Your Model Description'

partner_id = fields.Many2one('res.partner', string='Partner')
att = fields.Many2many('res.partner', string='Attendees')

@api.onchange('partner_id')
def _onchange_partner_id1(self):
for rec in self:
if rec.partner_id:
if rec.partner_id.is_company:
# If partner is a company, set domain to include all child partners (individuals)
rec.att = [(6, 0, rec.partner_id.child_ids.ids)]
return {
'domain': {'att': [('id', 'in', rec.partner_id.child_ids.ids)]}
}
else:
# If partner is an individual, set domain to include only that partner
rec.att = [(6, 0, [rec.partner_id.id])]
return {
'domain': {'att': [('id', '=', rec.partner_id.id)]}
}
else:
# If no partner is selected, clear the domain
rec.att = [(6, 0, [])]
return {
'domain': {'att': []}
}

Related Posts Răspunsuri Vizualizări Activitate
1
nov. 22
4036
2
oct. 24
1477
3
apr. 20
10478
1
iul. 25
520
0
dec. 20
4987