如何在向导中修改多对多字段?

时间:2016-04-01 14:51:03

标签: openerp

我的模型包含多对多的assign_to_id,我想在用户触发升级按钮时通过escalte_to方法以向导形式修改该字段

型号:

class Incident(models.Model):
    _name = 'itmangement.incident'
    assigned_to_id = fields.Many2one('hr.employee', string="Assigned To",domain="[('department_id', '=', dep_id)]",required=True)

向导模型

class Escalate(models.TransientModel):
    escalated_to = fields.Many2one('hr.employee', string="Escalated To", required=True)

        @api.one
        def escalate(self):

            incident_obj = self.env['itmangement.incident']
            record = incident_obj.browse(self._context.get('active_ids'))
            record.write({'state': 'escalated'})

1 个答案:

答案 0 :(得分:1)

class Escalate(models.TransientModel):
    escalated_to = fields.Many2one('hr.employee', string="Escalated To", required=True)

    @api.one
    def escalate(self):

        object_id = self.env.context.get('active_id')

        for object in self.env['itmangement.incident'].browse(object_id) and self.escalated_to:

            object.assigned_to_id = self.escalated_to.id