from odoo import api, fields, models, _
from odoo.exceptions import UserError


class ProjectCloseDate(models.TransientModel):
    _name = "back.date.assign"
    _description = "Timesheet Back Date Assign"

    start_date = fields.Date('Start Date')
    end_date = fields.Date('End Date')
    reason = fields.Text('Reason', required=True)
    permission_type = fields.Selection(string="Permission Type", selection=[('edit', 'Edit'), ('create', 'Create')],
                                       required=True)


    def action_compute_project_close(self):
        employee_obj = self.env['hr.employee'].browse(self._context.get('active_ids', []))
        print("employee_obj", employee_obj)
        employee_obj.permission_history.create({'employee_id': employee_obj.id,
                                                'start_date': self.start_date,
                                                'end_date': self.end_date,
                                                'permission_type': self.permission_type,
                                                'reason': self.reason,
                                                'user_id': self.env.uid})
