我想对这段代码进行解释:
@api.onchange('foyer_id')
def get_responsibles_members_foyer(self):
if self.foyer_id:
actually_foyer = self.foyer_id.foyer_id
partner_foyer = self.foyer_id.partner_id
if actually_foyer:
domain = [('foyer_id', '=', actually_foyer.id), ('partner_id', '=', partner_foyer.id)]
records_foyer_id = self.env['horanet.relation.foyer'].search(domain)
# Récupéré les membres du foyers via les ids
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:
print " " + rec_partner.partner_id.name
self.school_responsible_partner1 = rec_partner.partner_id.id
此功能的目的是恢复房屋中的负责成员,然后才能正常工作。 因此,我对字段foyer_id(Many2one)进行操作,当选择了房屋时,我在我的字段school_responsible_partner1
中得到了很好的价值。现在,我希望在使用以下代码打开表单时自动选择焦点:
@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
print self.foyer_id
此功能起作用是因为我的字段foyer_id是自动填充的。
但是,另一方面,在添加了最后一个函数之后,第一个函数(get_responsibles_members_foyer)不再起作用。
通过PyCharm调试,我注意到这一行:
partner_foyer = self.foyer_id.partner_id 他找到了一个新对象,而之前他找到了伙伴的ID。
您有解释吗?
谢谢