# -*- coding: utf-8 -*-
from odoo import models, fields, _


class RefuseReasonWizard(models.TransientModel):
    _name = 'service.refuse.reason.wizard'
    _description = 'Wizard to select a reason for service rejection'

    reason_id = fields.Many2one('service.refuse.reason', string="Reason", required=True)
    notes = fields.Text(string="Additional Notes", required=True)

    def action_confirm(self):
        service_request = self.env['service.request'].browse(self._context.get('active_id'))
        if service_request:
            service_request.write({
                'refuse_reason_id': self.reason_id.id,
                'refuse_reason': self.notes,
                'state': 'refused',
            })
            message = _("Request was refused.\nReason: %s\nNotes: %s") % (self.reason_id.name, self.notes)
            service_request.message_post(body=message, message_type='notification')
        return {'type': 'ir.actions.act_window_close'}
