# -*- coding: utf-8 -*-

from odoo import api, fields, models, _


class FusionLoanerCheckoutAssessment(models.Model):
    _inherit = 'fusion.loaner.checkout'

    assessment_id = fields.Many2one(
        'fusion.assessment',
        string='Assessment',
        ondelete='set null',
        tracking=True,
        help='Assessment during which this loaner was issued',
    )

    def action_view_assessment(self):
        self.ensure_one()
        if not self.assessment_id:
            return
        return {
            'name': self.assessment_id.display_name,
            'type': 'ir.actions.act_window',
            'res_model': 'fusion.assessment',
            'view_mode': 'form',
            'views': [(False, 'form')],
            'res_id': self.assessment_id.id,
        }
