Odoo 如何使用模型a字段中的onchange更新模型B中的字段?奥多12
我试图实现的是,当更新模型a中的字段时,我需要使用onchange方法更新模型B中的字段Odoo 如何使用模型a字段中的onchange更新模型B中的字段?奥多12,odoo,Odoo,我试图实现的是,当更新模型a中的字段时,我需要使用onchange方法更新模型B中的字段 _name = 'Model_A' health_profile = fields.Many2one('health.profile', domain="[('partner_id', '=', partner_id)]", string="Health Profile") @api.onchange('health_profile') def get
_name = 'Model_A'
health_profile = fields.Many2one('health.profile', domain="[('partner_id', '=', partner_id)]", string="Health Profile")
@api.onchange('health_profile')
def get_health_profile_specialist(self):
ctx = self.health_profile.id
res = self.env['model_B'].browse(ctx)
return res.update({'specialist_name': self.specialist_name})
据我所知,没有必要用onchange修改字段。您可以直接检查模型A字段中的值,也可以直接使用相关字段
health_profile = fields.Many2one('health.profile', domain="[('partner_id', '=', partner_id)]", string="Health Profile")
specialist_id = fields.Many2one('<yourmodel>', related='health_profile.specialist_id')
health\u profile=fields.manyOne('health.profile',domain=“[('partner\u id','=',partner\u id)],string=“health profile”)
专家id=字段.manyOne(“”,related='health\u profile.specialist\u id'))
也许你应该更好地解释自己。谢谢你的回复,我已经解决了,retrurn语句抛出了错误,现在运行正常。为什么write()方法不更新()?他们之间有什么区别?