I'm following my Python program and I'm trying to recover only records found via Python functions.
Here are my functions:
@api.onchange('partner_id')
def get_foyer(self):
if self.partner_id:
actually_partner_id = self.partner_id.name
if actually_partner_id:
records_foyer_id = self.env['horanet.relation.foyer'].search([('partner_id', '=', actually_partner_id)],
order="id desc")
for rec in records_foyer_id:
self.foyer_id = rec.id
@api.onchange('foyer_id')
def get_responsibles_members_foyer(self):
if self.foyer_id:
actually_foyer = self.foyer_id.foyer_id
if actually_foyer:
domain = [('foyer_id', '=', actually_foyer.id)]
records_foyer_id = self.env['horanet.relation.foyer'].search(domain)
for rec in records_foyer_id:
print " " + rec.partner_id.name
if rec.partner_id:
domain_partner = [('foyer_id', '=', self.foyer_id.foyer_id.id),
('is_responsible', '=', True)]
records_partner_id = self.env['horanet.relation.foyer'].search(domain_partner)
for rec_partner in records_partner_id:
if rec_partner.partner_id:
self.school_responsible_partner1 = rec_partner.partner_id.id
These functions serve two purposes:
-> automatically fill in the field foyer_id (recovery of a home) -> automatically fill in the field school_responsible_partner1 (recovery of the member responsible for this household)
Until then no problem.
However, when I roll out my 2 many2one fields, I get all homes or all members of any household. Do you have an idea to see only the recordings that interest me?
Attention, the same person can have 2 homes so I must be able to choose one of them.
I heard that it could happen in xml. But how ?
Thank you
Use domain in .xml file. Like this:
<field name="foyer_id" domain="[('partner_id', '=', partner_id)]"/>
You will then be able to choose foyer_id only that has a partner_id you have already assigned. But if you haven't chosen any partner_id, you will have no available foyer_id. In that case if you wish to select any, use "?=" operator instead of "=".
This will work only if you have a field named "partner_id" in the same form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.